Browse Source

++ts

master
Maxim Likhachev 5 years ago
parent
commit
24b5c8dc39
  1. 1
      README.md
  2. 26
      scripts/ts

1
README.md

@ -28,6 +28,7 @@ will create the symbolic link for each script in the \<path> directory. @@ -28,6 +28,7 @@ will create the symbolic link for each script in the \<path> directory.
- [fsz](scripts/fsz) adjusts console font size.
- [hr](scripts/hr) displays horizontal rule with current time.
- [renamepdfs](scripts/renamepdfs) renames PDF files using their metadata.
- [ts](scripts/ts) adds timestamps to command’s output.
- [vcat](scripts/vcat) displays file content with [syntax highlighting](https://www.gnu.org/software/src-highlite/) (see also [bat](https://github.com/sharkdp/bat)).
- [viper](scripts/viper) is a simple alternative to viper from [moreutils](https://joeyh.name/code/moreutils/) package which can be used with custom vim parameters.

26
scripts/ts

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Add timestamp to each line of the text output as moreutils/ts does.
rstc="\033[00m"
colour="\033[1;36m" # blue
usage() {
echo "USAGE: ${0##*/} [-n] [DATE FORMAT]"
echo " e.g. \`ping 127.0.0.1 | ts [%T]'"
}
for arg in "$@"; do
case "$arg" in
-h) usage; exit 0;;
-n) colour=""; rstc="";;
*) date_fmt="${arg}";;
esac
done
DATE_FORMAT="${date_fmt:-[%Y-%m-%d %T]}"
awk -v fmt="$DATE_FORMAT" -v colour="$colour" -v rstc="$rstc" '{
printf("%s%s%s %s\n", colour, strftime(fmt), rstc, $0)
}'
Loading…
Cancel
Save