aboutsummaryrefslogtreecommitdiff
path: root/mkshrc
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-01-22 20:22:08 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2021-01-23 11:02:04 -0500
commitcee85ee94fbcd38b2cd506f51e4308f81c622247 (patch)
treee2eebefbba46ab09df1936f7e2eb10d9a2264012 /mkshrc
parent9fb0d9bba9b51096be32c47a92e04c5199bdf3ab (diff)
downloaddotfiles-cee85ee94fbcd38b2cd506f51e4308f81c622247.tar.gz
dotfiles-cee85ee94fbcd38b2cd506f51e4308f81c622247.tar.xz
Update the shell configuration a bit
Diffstat (limited to 'mkshrc')
-rw-r--r--mkshrc128
1 files changed, 71 insertions, 57 deletions
diff --git a/mkshrc b/mkshrc
index 9e3ea8f..9800ef2 100644
--- a/mkshrc
+++ b/mkshrc
@@ -1,4 +1,4 @@
-# Copyright 2020 Mitchell Riedstra
+# Copyright 2021 Mitchell Riedstra
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -85,27 +85,28 @@ setaliases() {
}
setcoloraliases() {
- if [ `uname` = "Linux" ] ; then
+ if [ "$(uname)" = "Linux" ] ; then
alias ls="ls --color=auto -F";
alias lm='ls -lh --color=force | more';
- elif [ `uname` = "FreeBSD" ] ; then
+ elif [ "$(uname)" = "FreeBSD" ] ; then
alias ls="ls -FG";
alias lm='CLICOLOR_FORCE="1" ls -l | less -r';
fi
if echo "color test" | grep -q --color=auto "color test" >/dev/null 2>&1 ; then
alias grep="grep --color=auto";
- alias egrep='egrep --color=auto'
- alias search='egrep --color=auto -rnI';
+ alias egrep='grep -E --color=auto'
+ alias search='grep -E --color=auto -rnI';
fi
- alias diff="$(which diff colordiff 2>/dev/null | tail -n 1)";
+ #shellcheck disable=SC2139
+ alias diff="$(command -v diff colordiff 2>/dev/null | tail -n 1)";
alias t='tree -CdL'
}
setsudoaliases() {
# Prefer doas if available, as it's likely to be configured by me over sudo
- _sudo="$(which doas sudo 2>/dev/null | sed 1q)"
+ _sudo="$(command -v doas sudo 2>/dev/null | sed 1q)"
if [ -x "$_sudo" ] ; then
# Package managers
# Isn't it amazing how many distros you end up using?
@@ -151,23 +152,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";
@@ -190,9 +195,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 \
@@ -230,12 +235,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
}
@@ -258,20 +263,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"
}
@@ -357,7 +366,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" \
"\$@" \
}
@@ -388,6 +397,7 @@ gpgTmpDir() {
rm -rvf "$GNUPGHOME"
fi
+ #shellcheck disable=SC2155
export GNUPGHOME="$(mktemp -d /dev/shm/GPG.XXXXXX)"
set +x
}
@@ -467,7 +477,7 @@ pull() {
shift; shift; ;;
esac
done
- CMD="$(which curl wget fetch 2>/dev/null | tail -n1)"
+ CMD="$(command -v curl wget fetch 2>/dev/null | tail -n1)"
case $CMD in
*curl) "$CMD" "$url" > "$file" ;;
@@ -482,9 +492,9 @@ pulldotfile() {
}
_make_ssh_dir_if_not_exists() {
auth_keys="$HOME/.ssh/authorized_keys"
- if ! [ -d $HOME/.ssh ] ; then mkdir $HOME/.ssh ; fi
- chmod 700 $HOME/.ssh
- chmod 600 $auth_keys
+ if ! [ -d "$HOME/.ssh" ] ; then mkdir "$HOME/.ssh" ; fi
+ chmod 700 "$HOME/.ssh"
+ chmod 600 "$auth_keys"
}
_pullkeys() {
url="$1"; shift
@@ -498,7 +508,7 @@ _pullkeys() {
ssh-keygen -lf "$auth_keys" || \
mv "${auth_keys}.${_timestamp}" "$auth_keys"
- chmod 600 $auth_keys
+ chmod 600 "$auth_keys"
}
pullkeys() {
file="keys/$1"; shift;
@@ -512,20 +522,20 @@ pullkeys_github() {
}
pulltermcolors() {
file="$HOME/bin/terminal-colors"
- if ! [ -d $HOME/bin ] ; then
- mkdir $HOME/bin
+ if ! [ -d "$HOME/bin" ] ; then
+ mkdir "$HOME/bin"
fi
- pull -u ${UPDATE_URL}/util/terminal-colors -f $file
- chmod +x $file
+ pull -u "${UPDATE_URL}/util/terminal-colors" -f "$file"
+ chmod +x "$file"
}
updatetmuxconf() {
pulldotfile "tmux/tmux.conf"
pulldotfile "tmux/tmux_helper.sh"
- if ! [ -e $HOME/.tmux.conf.local ] && [ `id -u` -eq 0 ] ; then
+ if ! [ -e "$HOME/.tmux.conf.local" ] && [ "$(id -u)" -eq 0 ] ; then
# If I ever change the color from green this will have to be updated I guess
- grep 'green' $HOME/.tmux.conf | sed -e's/green/red/g' > $HOME/.tmux.conf.local
- elif ! [ -e $HOME/.tmux.conf.local ] ; then
- touch $HOME/.tmux.conf.local
+ grep 'green' "$HOME/.tmux.conf" | sed -e's/green/red/g' > "$HOME/.tmux.conf.local"
+ elif ! [ -e "$HOME/.tmux.conf.local" ] ; then
+ touch "$HOME/.tmux.conf.local"
fi
}
updategitconf() {
@@ -534,28 +544,29 @@ updategitconf() {
}
updateshell() {
pulldotfile "mkshrc"
- . $HOME/.mkshrc
+ #shellcheck disable=SC1090
+ . "$HOME/.mkshrc"
}
updatevimrc() {
OLDWD="$(pwd)"
+ #shellcheck disable=SC2164
cd "$HOME"
git clone --recurse-submodules "$VIM_GIT_URL" .vim
exit="$?"
- cd $HOME/.vim || { echo "Cannot cd to .vim dir" ; return; }
+ cd "$HOME/.vim" || { echo "Cannot cd to .vim dir" ; return; }
if [ "$exit" -gt 0 ] ; then
git pull origin master
git submodule update
fi
./link-vimrc.sh
- cd $OLDWD
+ #shellcheck disable=SC2164
+ cd "$OLDWD"
}
updatevimrc_basic() {
pull -u "$VIM_BASIC_URL" -f ~/.vimrc
}
-
-
SHELL_CONFIG=".mkshrc"
COLOR=0
case "$TERM" in
@@ -577,8 +588,9 @@ LOCAL="$HOME/${SHELL_CONFIG}.local"
# functions if you do that
# Load pre config
-if [ -e $PRELOAD ] ; then
- . $PRELOAD
+if [ -e "$PRELOAD" ] ; then
+ #shellcheck disable=SC1090
+ . "$PRELOAD"
fi
set_pager
@@ -595,20 +607,22 @@ setsudoaliases
# Nasty conditional for support of many different shells
if
- ! [ -z "$KSH_VERSION" ] ||
- [ $SHELL = "/bin/ksh" ] ||
- [ $SHELL = "/bin/mksh" ] ||
- [ $SHELL = "/usr/bin/mksh" ] ||
- [ $SHELL = "/usr/local/bin/mksh" ]
+ [ -n "$KSH_VERSION" ] ||
+ [ "$SHELL" = "/bin/ksh" ] ||
+ [ "$SHELL" = "/bin/mksh" ] ||
+ [ "$SHELL" = "/usr/bin/mksh" ] ||
+ [ "$SHELL" = "/usr/local/bin/mksh" ]
then
export HISTFILE="$HOME/.ksh_history"
set -o emacs
bind ^L=clear-screen
+ #shellcheck disable=SC2155
export PS1="$(whoami)@$(hostname) \$PWD \$ "
-elif [ $SHELL = "/bin/sh" ] && [ "$(uname)" = "FreeBSD" ] ; then
+elif [ "$SHELL" = "/bin/sh" ] && [ "$(uname)" = "FreeBSD" ] ; then
set -o emacs
+ #shellcheck disable=SC2155
export PS1="$(whoami)"'@\h:\w \$ '
-elif ! [ -z "$BASH" ] ; then
+elif [ -n "$BASH" ] ; then
HISTFILE="$HOME/.bash_history"
HISTSIZE=10000
HISTFILESIZE=10000
@@ -624,6 +638,6 @@ if [ $COLOR -eq 1 ] ; then
fi
# Include local configuration options
-if [ -f $LOCAL ] ; then
- . $LOCAL
+if [ -f "$LOCAL" ] ; then
+ . "$LOCAL"
fi