Skip to main content

See output/input status of all sub-folders

Project description

PyPi version licence PyPI - Downloads

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

  1. manage (CRUD) templates
  2. run template command with substitutions
  3. 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

  1. folder name pattern: *_5/
  2. 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

  • run command
    • coi run -i <i> -c <c> -o <o> -t <name> <path>: run template command <name>
  • templates command
    • coi 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 template
    • coi 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coi-0.0.8.tar.gz (9.1 kB view details)

Uploaded Source

File details

Details for the file coi-0.0.8.tar.gz.

File metadata

  • Download URL: coi-0.0.8.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for coi-0.0.8.tar.gz
Algorithm Hash digest
SHA256 089f3dd9aa04dcfbb25ee55da90808ced78b935b7adf723d87d97308dd40e2a9
MD5 bcbfcb4b3f5a8078ee1cd33b4bbc7b3c
BLAKE2b-256 f296e0f5f4e1bfd22bc160bb747e85445a022dcb75e0b07de752e2054dc85258

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page