aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-02 00:24:39 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-02 00:24:39 +1200
commitef9a12e780efdd1eb0ddcb745b9d93e312353b73 (patch)
tree52672882a2f8c89cd76ef5df0ef706e8bbb933d5 /bash/bashrc.d
parentTerser pa/paz implementations (diff)
downloaddotfiles-ef9a12e780efdd1eb0ddcb745b9d93e312353b73.tar.gz
dotfiles-ef9a12e780efdd1eb0ddcb745b9d93e312353b73.zip
Use set rather than building arg arrays
Allows for terser functions and avoids error-prone local variables; also nicer to have a single `command` call at the end of the function (although there are still two at the end of the ed(1) wrapper)
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r--bash/bashrc.d/ed.bash25
-rw-r--r--bash/bashrc.d/gpg.bash11
-rw-r--r--bash/bashrc.d/pwgen.bash7
-rw-r--r--bash/bashrc.d/sudo.bash7
-rw-r--r--bash/bashrc.d/tmux.bash9
5 files changed, 27 insertions, 32 deletions
diff --git a/bash/bashrc.d/ed.bash b/bash/bashrc.d/ed.bash
index 0f069b85..4653743b 100644
--- a/bash/bashrc.d/ed.bash
+++ b/bash/bashrc.d/ed.bash
@@ -4,26 +4,23 @@
# it's available.
ed() {
- # Options for ed(1), and a command string in which to wrap the call if
- # appropriate
- local -a opts wrap
-
+ # We're only adding options if input is from a terminal
if [[ -t 0 ]] ; then
- # Assemble options for interactive use: colon prompt, and verbose if
- # available (-p is POSIX, but -v is not)
- opts=(-p :)
- if ed -sv - </dev/null >&0 2>&0 ; then
- opts[${#opts[@]}]=-v
- fi
+ # Colon prompt (POSIX)
+ set -- -p : "$@"
- # Use rlwrap(1) if it's available, but don't throw a fit if it isn't
- if hash rlwrap 2>/dev/null ; then
- wrap=(rlwrap)
+ # Verbose if availble (not POSIX)
+ if ed -sv - </dev/null >&0 2>&0 ; then
+ set -- -v "$@"
fi
fi
# Execute the ed(1) call, in a wrapper if appropriate and with the
# concluded options
- command "${wrap[@]}" ed "${opts[@]}" "$@"
+ if [[ -t 0 ]] && hash rlwrap 2>/dev/null ; then
+ command rlwrap ed "$@"
+ else
+ command ed "$@"
+ fi
}
diff --git a/bash/bashrc.d/gpg.bash b/bash/bashrc.d/gpg.bash
index 446475dc..28c5b722 100644
--- a/bash/bashrc.d/gpg.bash
+++ b/bash/bashrc.d/gpg.bash
@@ -1,15 +1,12 @@
# Wrapper around gpg(1) to stop ``--batch'' breaking things
gpg() {
- local argstring
- argstring=$*
- case $argstring in
+ # shellcheck disable=SC2048
+ case $* in
*--ed*|*--gen-k*|*--sign-k*)
- command gpg --no-batch "$@"
- ;;
- *)
- command gpg "$@"
+ set -- --no-batch "$@"
;;
esac
+ command gpg "$@"
}
# Completion for gpg with long options
diff --git a/bash/bashrc.d/pwgen.bash b/bash/bashrc.d/pwgen.bash
index f57d1884..7ba056e5 100644
--- a/bash/bashrc.d/pwgen.bash
+++ b/bash/bashrc.d/pwgen.bash
@@ -1,9 +1,8 @@
# Set some defaults for pwgen(1), because its defaults are to give me a long
# list of relatively short passwords, when I generally want only one good one
pwgen() {
- if (($#)) ; then
- command pwgen "$@"
- else
- command pwgen --secure -- "${PWGEN_LENGTH:-15}" "${PWGEN_COUNT:-1}"
+ if ! (($#)) ; then
+ set -- --secure -- "${PWGEN_LENGTH:-15}" "${PWGEN_COUNT:-1}"
fi
+ command pwgen "$@"
}
diff --git a/bash/bashrc.d/sudo.bash b/bash/bashrc.d/sudo.bash
index 5bb8906a..d6d91d12 100644
--- a/bash/bashrc.d/sudo.bash
+++ b/bash/bashrc.d/sudo.bash
@@ -1,8 +1,7 @@
# Add the -H parameter to sudo(8) calls, always use the target user's $HOME
sudo() {
- if [[ $1 == -v ]] ; then
- command sudo "$@"
- else
- command sudo -H "$@"
+ if [[ $1 != -v ]] ; then
+ set -- -H "$@"
fi
+ command sudo "$@"
}
diff --git a/bash/bashrc.d/tmux.bash b/bash/bashrc.d/tmux.bash
index c70a7908..f0d0e36a 100644
--- a/bash/bashrc.d/tmux.bash
+++ b/bash/bashrc.d/tmux.bash
@@ -3,14 +3,17 @@ tmux() {
# If given any arguments, just use them as they are
if (($#)) ; then
- command tmux "$@"
+ :
# If a session exists, just attach to it
elif command tmux has-session 2>/dev/null ; then
- command tmux attach-session -d
+ set -- attach-session -d
# Create a new session with an appropriate name
else
- command tmux new-session -s "${TMUX_SESSION:-default}"
+ set -- new-session -s "${TMUX_SESSION:-default}"
fi
+
+ # Execute with concluded arguments
+ command tmux "$@"
}