From 573bf2722fa9151143abc7a658f5285b80277374 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 21 Nov 2016 23:58:53 -0500 Subject: [PATCH] Refactor bin scripts --- bin/2png | 4 ++-- bin/calc | 2 +- bin/lsarchive | 16 ++++++---------- bin/replace | 4 ++-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/bin/2png b/bin/2png index 12bd198d..376f1747 100755 --- a/bin/2png +++ b/bin/2png @@ -1,11 +1,11 @@ -#!/usr/bin/env zsh +#!/usr/bin/env bash # Creates pngs from PSD (and AI) files. Requires imagemagick (and ghostscript # for ai files) # Usage: 2png *.{psd,ai} -[[ ! -d _png ]] && mkdir -p _png; +[[ -d _png ]] || mkdir -p _png; for f in $1 do diff --git a/bin/calc b/bin/calc index d4818987..857196cd 100755 --- a/bin/calc +++ b/bin/calc @@ -1,5 +1,5 @@ #!/usr/bin/env bash bc -l <<< "$@" # usage: -# bc 25 + 25 +# calc 25 + 25 # => 50 diff --git a/bin/lsarchive b/bin/lsarchive index 0396b992..f3cc5f3e 100755 --- a/bin/lsarchive +++ b/bin/lsarchive @@ -1,11 +1,10 @@ #!/usr/bin/env bash -# + # Lists the contents of archives. # # Adapted from a script by Sorin Ionescu -if (( $# == 0 )) -then +if (($# == 0)); then cat >&2 <. EOF fi -if [[ "$1" == "-v" || "$1" == "--verbose" ]] -then +if [[ $1 = -v || $1 = --verbose ]]; then verbose=0 shift fi -while (( $# > 0 )) -do - if [[ ! -s "$1" ]] - then +while (($# > 0)); do + if [[ ! -s $1 ]]; then >&2 echo "$0: file not valid: $1" shift continue fi - case "${1:l}" in + case ${1:l} in *.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;; *.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;; *.tar.xz|*.txz) tar --xz --help &> /dev/null \ diff --git a/bin/replace b/bin/replace index 1601829b..8c2a906d 100755 --- a/bin/replace +++ b/bin/replace @@ -7,8 +7,8 @@ find_this="$1"; shift replace_with="$1"; shift -items=$(ag -l --nocolor "$find_this" "$@") +items=( $(ag -l --nocolor "$find_this" "$@") ) temp="${TMPDIR:-/tmp}/replace_tmp.$$" -for item in $items; do +for item in ${items[@]}; do sed "s/$find_this/$replace_with/g" "$item" > "$temp" && mv "$temp" "$item" done