Shutils
My shell utilities
Install / Use
/learn @jonsim/ShutilsREADME
Table of Contents
- shutils
- Dependencies
- Installation
- License
- Documentation
- b2r
- check-links
- d2h
- git-compare-branch
- h2d
- json-print
- prepend
- tabulate
- tcgdb
- timeit
- wcz
- xwinid
shutils
Collection of my sh utils, for use in all POSIX compliant shells. All applications have been implemented either as a POSIX compliant sh script, or as a Python script requiring at most Python 2.7.
© Copyright 2017 Jonathan Simmonds
Dependencies
- Python 2.7+
Installation
TODO
License
All files are licensed under the MIT license.
Documentation
b2r
Type
Python script
Usage
usage: b2r [-h] [number-of-bytes]
Tiny program to convert a raw number of bytes (either decimal or
prefixed hex) into a human readable form.
positional arguments:
number-of-bytes Number of bytes to convert. May be ommitted to
read from stdin.
optional arguments:
-h, --help Print this message and exit.
Examples
b2r 1234567890
1.15G
echo 0x512 | b2r
1.27K
check-links
Type
POSIX shell script
Usage
usage: check-links [-p] [-h] [directory]
Simple application to confirm the validity of symlinks in a directory.
positional arguments:
directory Optional directory to search in. If ommitted the current
working directory is used.
optional arguments:
-p Run in script mode, outputing just the name of all
broken links to stdout. In interactive mode (default)
output is decorated.
-h, --help Print this message and exit.
Examples
touch real-file.txt
ln -s real-file.txt real-link.txt
ln -s fake-file.txt fake-link.txt
check-links
WARNING: link './fake-link.txt' is broken.
rm real-file.txt
check-links -p .
./real-link.txt
./fake-link.txt
d2h
Type
Python script
Usage
usage: d2h [-h] [number]
Tiny program to convert a number in decimal to hex.
positional arguments:
number decimal number. May be ommitted to read from stdin.
optional arguments:
-h, --help Print this message and exit.
Examples
d2h 42
0x2a
echo 1234 | d2h
0x4d2
git-compare-branch
Type
Python script
Usage
usage: git-compare-branch [-h] [-b] [-n [NUMBER]] [-e] [-m [PATTERN]]
[-u [PATTERN]] [--loose-merge-pattern] [-p] [-s]
[-S] [-c] [-C] [-f] [-F] [-g] [-G]
BRANCH-A BRANCH-B
Finds commits on branch B which are not on branch A. This is able to handle if
B has already been merged down to A. This command runs purely locally and as
such the branches to compare should be checked out and up to date before
running. No state is changed by running this.
positional arguments:
BRANCH-A Branch A. This is the branch against which the
difference is taken. It must exist locally.
BRANCH-B Branch B. This is the branch whose differences are
recorded. It must either exist locally or have a
corresponding merge commit onto A within the lookback
distance. See --merge-pattern and --lookback for
details on identifying merge commits and setting the
lookback respectively.
optional arguments:
-h, --help show this help message and exit
-b, --both-ways Print not only the differences from B to A (the
default), but also the differences from A to B.
-n [NUMBER], --lookback [NUMBER]
Sets the number of commits to consider in the history.
The lookback distance must cover the full lifetime of
the branch (i.e. to the fork point). May be set to 0
to consider all history (on large repositorys this may
take some time). Defaults to 1000.
-e, --exclude-updates
Exclude update commits (merges from A back to B) from
all differences. By default all differences are
considered.
-m [PATTERN], --merge-pattern [PATTERN]
The stem merge commit pattern to identify the merge
commit from B to A. This is only necessary if B does
not exist. Defaults to the standard git merge pattern
"Merge branch". The merge commit's subject must
contain the pattern followed by the merged branch
name. It is matched with the following regex:
^PATTERN.*BRANCH_B.*$
-u [PATTERN], --update-pattern [PATTERN]
The stem merge commit pattern to identify any 'update'
merge commits from A to B. This is only necessary if
using --exclude-updates and if this pattern differs
from --merge-pattern. Defaults to the value given in
--merge-pattern. All 'update' merge commit subjects
must contain the pattern followed by A's name followed
by B's name. It is matched with the following regex:
^PATTERN.*BRANCH_A.*$
--loose-merge-pattern
Exclude the branchname from the merge and update
patterns (so they match just the pattern given). By
default the branchname is included.
-p, --pretty Print a short hash and the subject for all commits. By
default just the full hash is printed.
-s, --summary Print a summary of the status of each branch and their
relationship. This is the default.
-S, --no-summary Do not print the summary list (see --summary).
-c, --commits Print a list of all commits which exist on branch B
but not branch A. This is the default.
-C, --no-commits Do not print the commit list (see --commits).
-f, --finger Print a list of all users who have made commits on
branch B.
-F, --no-finger Do not print the finger list (see --finger). This is
the default.
-g, --graph Print a chronological graph of the commits made to
branches A and B during their lifetime. This only has
an effect if branch B has been merged into branch A,
otherwise ignored. Corresponds to the --graph option
of git log.
-G, --no-graph Do not print the commit graph (see --graph). This is
the default.
Examples
git branch
* master
topic2
topic3
git log --format=oneline --abbrev-commit --date-order
0ff720c Merge branch 'topic3'
1bddb09 N (master)
ff2fa26 Merge branch 'master' into topic3
4517b81 M (topic3)
48adb5a L (master)
14dbda6 K (master)
c3e48a2 I (master)
26a1f0d Merge branch 'topic1'
812f773 H (topic1)
d129d72 Merge branch 'master' into topic1
d1bb781 G (topic1)
f8556f0 E (master)
558f44b F (topic1)
c5aaaa9 D (master)
48b70ff C (master)
7292420 B (master)
d782883 A ()
git-compare-branch master topic3
Summary:
topic3 still exists
topic3 forked from master at: 14dbda6586c492639f47c6591b63fbd06e74a363
Commits made on topic3 but not master:
ff2fa26b1cf17a510b7fc88eb7085b24d53bcf73
4517b814b7703d7364fd44f736bcb4b5e17be023
git-compare-branch master topic1 --pretty
Summary:
topic1 no longer exists
topic1 merged into master at: 26a1f0d8a6c6cddaff2bdd6c7a96430af364cee6
topic1 forked from master at: c5aaaa948f48d1b8e8e86b850baa1274458da410
Commits made on topic1 but not master:
812f773 [Fri Jul 24 15:59:55 2020 +0100] H (topic1)
d129d72 [Fri Jul 24 15:59:55 2020 +0100] Merge branch 'master' into topic1
d1bb781 [Fri Jul 24 15:59:55 2020 +0100] G (topic1)
558f44b [Fri Jul 24 15:59:55 2020 +0100] F (topic1)
git-compare-branch master topic1 --both-ways --pretty --summary --commits --finger --graph
Summary:
topic1 no longer exists
topic1 merged into master at: 26a1f0d8a6c6cddaff2bdd6c7a96430af364cee6
topic1 forked from master at: c5aaaa948f48d1b8e8e86b850baa1274458da410
Commits made on topic1 but not master:
812f773 [Fri Jul 24 15:59:55 2020 +0100] H (topic1)
d129d72 [Fri Jul 24 15:59:55 2020 +0100] Merge branch 'master' into topic1
d1bb781 [Fri Jul 24 15:59:55 2020 +0100] G (topic1)
558f44b [Fri Jul 24 15:59:55 2020 +0100] F (topic1)
Commits made on master but not topic1:
f8556f0 [Fri Jul 24 15:59:55 2020 +0100] E (master)
Authors of commits on topic1 but not master:
4 Jonathan Simmonds <jonathansimmonds@gmail
