aboutsummaryrefslogtreecommitdiff
path: root/shell/utils
diff options
context:
space:
mode:
Diffstat (limited to 'shell/utils')
-rw-r--r--shell/utils51
1 files changed, 30 insertions, 21 deletions
diff --git a/shell/utils b/shell/utils
index 5a74a58..4e60989 100644
--- a/shell/utils
+++ b/shell/utils
@@ -12,23 +12,27 @@ set_go() {
export PATH="$_gobin:$PATH"
fi
}
-set_editor() {
- if [ -z "$EDITORS" ] ; then
- export EDITORS="ed vi vim"
- fi
-
- export EDITOR="$(which $EDITORS 2>/dev/null | tail -n1)"
-
- export VISUAL="$EDITOR"
-
- # Set an alias for our editor of choice
+_set_editor() {
+ export EDITOR="$1"
+ export VISUAL="$1"
alias vi="$EDITOR"
alias vim="$EDITOR"
alias edit="$EDITOR"
alias e="$EDITOR"
}
+set_editor() {
+ for editor in vim vi ed ; do
+ unalias "$editor" >/dev/null 2>&1
+ e="$(command -v "$editor")"
+ if [ -n "$e" ] && [ -x "$e" ] ; then
+ _set_editor "$e"
+ fi
+ break
+ done
+}
set_pager() {
- export PAGER="$(which cat more less 2>/dev/null | tail -n1)"
+ #shellcheck disable=SC2155
+ export PAGER="$(command -v cat more less 2>/dev/null | tail -n1)"
}
set_lang() {
export CHARSET="$1";
@@ -51,9 +55,9 @@ randmacgen() {
}
# First argument is the interface on which to scan
ipv6_local_hosts() {
-if ! [ -z $1 ] ; then
+if [ -n "$1" ] ; then
interface="$1"
- ping6 -c 3 ff02::2%$interface \
+ ping6 -c 3 "ff02::2%$interface" \
| grep 'bytes from' \
| awk '{print $4}' \
| sort \
@@ -91,12 +95,12 @@ set_my_title() {
}
_sys_memory() {
- ! [ -e $(which vmstat) ] && return
- if [ `uname` = "Linux" ] ; then
+ ! [ -e "$(command -v vmstat)" ] && return
+ if [ "$(uname)" = "Linux" ] ; then
vmstat | tail -n1 | awk '{print $4/1024}' | sed -e's/\..*$//g'
- elif [ `uname` = "FreeBSD" ] ; then
+ elif [ "$(uname)" = "FreeBSD" ] ; then
vmstat | tail -n1 | awk '{print $5/1024}' | sed -e's/\..*$//g'
- elif [ `uname` = "OpenBSD" ] ; then
+ elif [ "$(uname)" = "OpenBSD" ] ; then
vmstat | sed -n '$p' | awk '{print $4}' | sed 's/M$//'
fi
}
@@ -119,20 +123,24 @@ timestamp() {
checkSSHAgent() {
ssh_agent_conf="$HOME/.ssh/agent"
if [ -e "$ssh_agent_conf" ] ; then
- . "$ssh_agent_conf"
+ #shellcheck disable=SC1090
+ . "$ssh_agent_conf"
fi
+ #shellcheck disable=SC2009
if ! ps -eo pid | grep -q "$SSH_AGENT_PID" \
|| ! [ -e "$ssh_agent_conf" ] \
|| [ -z "$SSH_AGENT_PID" ] ; \
then
- ssh-agent -s | grep -v echo > "$ssh_agent_conf"
- . "$ssh_agent_conf"
+ ssh-agent -s | grep -v echo > "$ssh_agent_conf"
+ #shellcheck disable=SC1090
+ . "$ssh_agent_conf"
fi
}
passenv() {
_f="$(mktemp)"
pass "$@" > "$_f"
+ #shellcheck disable=SC1090
. "$_f"
rm -f "$_f"
}
@@ -218,7 +226,7 @@ layout="select-layout $layout ';' set-window-option synchronize-panes on ';'"
eval _tmux_session -s "\$session" -w "\$working_directory" -n "main" \
-- \
$(_tmux_servers_split_commands $servers) \
- $layout \
+ "$layout" \
"\$@" \
}
@@ -249,6 +257,7 @@ gpgTmpDir() {
rm -rvf "$GNUPGHOME"
fi
+ #shellcheck disable=SC2155
export GNUPGHOME="$(mktemp -d /dev/shm/GPG.XXXXXX)"
set +x
}