Refactor bin scripts

This commit is contained in:
Henrik Lissner 2016-11-21 23:58:53 -05:00
parent 639fa8e1c2
commit 573bf2722f
4 changed files with 11 additions and 15 deletions

View file

@ -1,11 +1,11 @@
#!/usr/bin/env zsh #!/usr/bin/env bash
# Creates pngs from PSD (and AI) files. Requires imagemagick (and ghostscript # Creates pngs from PSD (and AI) files. Requires imagemagick (and ghostscript
# for ai files) # for ai files)
# Usage: 2png *.{psd,ai} # Usage: 2png *.{psd,ai}
[[ ! -d _png ]] && mkdir -p _png; [[ -d _png ]] || mkdir -p _png;
for f in $1 for f in $1
do do

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
bc -l <<< "$@" bc -l <<< "$@"
# usage: # usage:
# bc 25 + 25 # calc 25 + 25
# => 50 # => 50

View file

@ -1,11 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# Lists the contents of archives. # Lists the contents of archives.
# #
# Adapted from a script by Sorin Ionescu <sorin.ionescu@gmail.com> # Adapted from a script by Sorin Ionescu <sorin.ionescu@gmail.com>
if (( $# == 0 )) if (($# == 0)); then
then
cat >&2 <<EOF cat >&2 <<EOF
usage: $0 [-option] [file ...] usage: $0 [-option] [file ...]
@ -16,22 +15,19 @@ Report bugs to <sorin.ionescu@gmail.com>.
EOF EOF
fi fi
if [[ "$1" == "-v" || "$1" == "--verbose" ]] if [[ $1 = -v || $1 = --verbose ]]; then
then
verbose=0 verbose=0
shift shift
fi fi
while (( $# > 0 )) while (($# > 0)); do
do if [[ ! -s $1 ]]; then
if [[ ! -s "$1" ]]
then
>&2 echo "$0: file not valid: $1" >&2 echo "$0: file not valid: $1"
shift shift
continue continue
fi fi
case "${1:l}" in case ${1:l} in
*.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;; *.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;;
*.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;; *.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;;
*.tar.xz|*.txz) tar --xz --help &> /dev/null \ *.tar.xz|*.txz) tar --xz --help &> /dev/null \

View file

@ -7,8 +7,8 @@
find_this="$1"; shift find_this="$1"; shift
replace_with="$1"; shift replace_with="$1"; shift
items=$(ag -l --nocolor "$find_this" "$@") items=( $(ag -l --nocolor "$find_this" "$@") )
temp="${TMPDIR:-/tmp}/replace_tmp.$$" 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" sed "s/$find_this/$replace_with/g" "$item" > "$temp" && mv "$temp" "$item"
done done