coi: manage shell script templates for reuse
I often improvise the same (boring) bash scripts over and over again. This is my solution to cut the repetitive work.
This command-line tool can
- manage (CRUD) templates
- run template command with substitutions
- keep track of commands run in each folder for later reference
examples
Three examples are in order here.
They are all small frequent for loops.
One could alternatively define shell functions for them.
In the first example, I need to delete jobs with some key word. The varying part
is BIHYEW10.
for x in `qstat -u nosarthur |grep BIHYEW10 |awk '{print $1}'`; do
qdel $x
done
With coi set up, I can simply do
coi run -i BIHYEW10
The corresponding template is
for x in `qstat -u nosarthur |grep $i |awk '{print $$1}'`; do
qdel $$x
done
Note that it's simply the Python [template strings](https://docs.python.org/3/library/string.html#template-strings ]).
In the second example, I often need to process data with a common directory
pattern, e.g., ABC_5/ABC-out.cms:
for dname in *_5/; do python3 process.py $dname${dname%/}-out.cms; done
Here the variable parts are
- folder name pattern:
*_5/ - command:
$ABIN/generate.py
After saving a template, we can run
coi run -i "*_5" -c "python3 process.py" some-path
and the template is
cd $path
for dname in $i; do
$c $$dname$${dname%/}-out.cms
done
where some-path will substitute $path.
In the third example, I often want to know how many jobs are done in many folders, and the criteria of 'done' may vary.
Suppose the folder structure is as follows
jobs-folder
├── sub1
│ ├── 1.input
│ ├── 1.output
│ └── 2.input
├── sub2
│ ├── 1.input
│ └── 2.input
├── sub3
│ ├── 1.input
│ ├── 1.output
│ ├── 2.input
│ └── 2.output
└── sub4
├── 1.input
└── 1.output
coi -c "wc -l" \
-o "ll *.output" \
-i "ll *.input" \
jobs-folder
commands
runcommandcoi run -i <i> -c <c> -o <o> -t <name> <path>: run template command<name>
templatescommandcoi templates add <name>: create a new template called<name>coi templates cp <name> <new-name>: copy<name>to a new template called<new-name>coi templates ll <name>: show content of template<name>coi templates ls <name>: show path of template<name>; You can pass it to your favorate editor.coi templates rm <name>: delete template<name>coi templates set <name>: set template<name>as default templatecoi templates set: show default template name
The run command takes up to 3 parameters c, 'o', and 'i'. If template -t
is not specified, default template is used. If <path> is omitted, current
working directory is used.
customization
User defined templates are saved/searched in $XDG_CONFIG_HOME/coi
(most likely ~/.config/coi/).
other tune-ups
alias coir='coi run'
alias coit='coi template'
design
Essentially this is a tool for shell script templating, with up to 3 substitutions.
- templates are saved in
- system folder: default
- XDG/coi/templates/: user defined
- the user defined templates shadow default ones if name clashes
TODO:
- default template
- auto complete for templates
integration with fzf
If json files exists in a path, we can let the user pick with fzf
Metadata
Release files for coi 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| coi-0.0.8.tar.gz | 9.1 kB | Without provenance | Details |
Release files / coi-0.0.8.tar.gz
| Download URL | coi-0.0.8.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
089f3dd9aa04dcfbb25ee55da90808ced78b935b7adf723d87d97308dd40e2a9
|
|
BLAKE2b-256 checksum How to use checksums |
f296e0f5f4e1bfd22bc160bb747e85445a022dcb75e0b07de752e2054dc85258
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.10
|
Security for coi 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.