dotfiles

Obligatory dotfiles repo
git clone git://git.danielmoch.com/dotfiles.git
Log | Files | Refs

commit b29d81ae5f0284838317b3ca710f8854c7583cec
parent c2a062ca0b25a20be5cd8f6dd7705bcd40a0988e
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Tue, 16 Jan 2018 11:41:33 +0000

Posix shell compliance

'type -p' fails in dash, so just use 'type' to test whether or not
something exists in $PATH.

The double-equal string comparison operator is also not recognized by
dash, so use a single equal sign.

Diffstat:
M.lessfilter | 4++--
M.local/bin/my-init | 19+++++++++++--------
M.local/bin/my-open | 8++++----
M.profile | 10+++++-----
M.shrc | 14+++++++-------
5 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/.lessfilter b/.lessfilter @@ -1,7 +1,7 @@ #!/bin/sh __pygmentize () { - if which pygmentize > /dev/null 2>&1 + if type pygmentize > /dev/null 2>&1 then if [ -n "$2" ] then @@ -16,7 +16,7 @@ __pygmentize () if [ -d "$1" ] then - if which dircolors > /dev/null 2>&1 + if type dircolors > /dev/null 2>&1 then ls -lA --color=force "$1" else diff --git a/.local/bin/my-init b/.local/bin/my-init @@ -10,20 +10,23 @@ __has() { for token in $@ do - type -p $token > /dev/null 2>&1 - [ $? -ne 0 ] && return 1 + type $token > /dev/null 2>&1 + [ $? -ne 0 ] && echo "$token doesn't exist" && return 1 done return 0 } __clone() { + echo -n " Cloning $1 ... " git clone https://github.com/$1.git > /dev/null 2>&1 + [ $? -ne 0 ] && echo "FAILED!" && return 1 + echo "Succeeded" } echo "Performing run-once initializations" -if [ -n "$1" -a "$1" == "-f" ] +if [ -n "$1" -a "$1" = "-f" ] then echo " Re-initialization requested" rm -f "$HOME/._.djmoch" @@ -33,7 +36,7 @@ then fi # Terminfo -if __has "infocmp" "tic" && [ ! -d "$HOME/.terminfo" ] +if __has "infocmp" "tic" && [ ! -d "$HOME/.terminfo" ] then echo " Initializing Termcaps" if infocmp tmux-256color > /dev/null 2>&1 @@ -56,8 +59,8 @@ if __has "git" && [ ! -d "$vim_bundle_path" ] then echo " Downloading Vim plugins" # Plugins that should always be enabled - mkdir -p bundle/start - cd bundle/start + mkdir -p $vim_bundle_path/start + cd $vim_bundle_path/start __clone romainl/Apprentice __clone tpope/vim-commentary __clone tpope/vim-eunuch @@ -79,8 +82,8 @@ then cd - > /dev/null 2>&1 # Plugins used optionally - mkdir -p bundle/opt - cd bundle/opt + mkdir -p $vim_bundle_path/opt + cd $vim_bundle_path/opt __clone jpalardy/vim-slime cd - > /dev/null 2>&1 fi diff --git a/.local/bin/my-open b/.local/bin/my-open @@ -10,18 +10,18 @@ # # Find handler, if one is available -if type -p cygstart > /dev/null 2>&1 +if type cygstart > /dev/null 2>&1 then handler=cygstart -elif type -p exo-open > /dev/null 2>&1 +elif type exo-open > /dev/null 2>&1 then handler=exo-open -elif type -p xdg-open > /dev/null 2>&1 +elif type xdg-open > /dev/null 2>&1 then handler=xdg-open # Because of its ambiguity, open (the macOS handler) should always be # tested last -elif type -p open > /dev/null 2>&1 +elif type open > /dev/null 2>&1 then handler=open else diff --git a/.profile b/.profile @@ -3,12 +3,12 @@ # [ -r "$HOME/.profile.local" ] && . "$HOME/.profile.local" -if [ "$0" == "sh" -o "$0" == "-sh" ] +if [ "$0" = "sh" -o "$0" = "-sh" ] then ENV="$HOME/.shrc"; export ENV fi -if type -p vim > /dev/null 2>&1 +if type vim > /dev/null 2>&1 then EDITOR=vim else @@ -20,7 +20,7 @@ PAGER=less LESS="-FMRqX#10" export EDITOR VISUAL PAGER LESS -if type -p lesspipe > /dev/null 2>&1 +if type lesspipe > /dev/null 2>&1 then eval `lesspipe` else @@ -29,7 +29,7 @@ else fi # Keep the go folder hidden -if type -p go > /dev/null 2>&1 +if type go > /dev/null 2>&1 then GOPATH="$HOME/.go" export GOPATH @@ -61,7 +61,7 @@ __addpath "$HOME/.local/bin" "before" unset __addpath export PATH -if type -p my-init > /dev/null 2>&1 && [ ! -f "$HOME/._.djmoch" ] +if type my-init > /dev/null 2>&1 && [ ! -f "$HOME/._.djmoch" ] then my-init fi diff --git a/.shrc b/.shrc @@ -17,7 +17,7 @@ fi export PS1 # Turn on ls colors -if type -p dircolors > /dev/null 2>&1 +if type dircolors > /dev/null 2>&1 then if [ -n "$SOURCE_DIRCOLORS" ] then @@ -35,14 +35,14 @@ fi COLORIZE_CMDS="pacman grep egrep fgrep" for cmd in $COLORIZE_CMDS do - if type -p $cmd > /dev/null 2>&1 + if type $cmd > /dev/null 2>&1 then alias $cmd="$cmd --color=auto" fi done # Handy Tmux aliases -if type -p tmux > /dev/null 2>&1 +if type tmux > /dev/null 2>&1 then alias tas=tmux\ attach-session\ -t alias tns=tmux\ new-session\ -s @@ -52,14 +52,14 @@ fi alias export="export -p" # Configure GPG and start the agent if it isn't already running -if type -p gpg-connect-agent > /dev/null 2>&1 +if type gpg-connect-agent > /dev/null 2>&1 then export GPG_TTY=`tty` gpg-connect-agent updatestartuptty /bye > /dev/null 2>&1 # Configure GPG as an SSH key provider # Assume SSH agent is forwarded if we're in an SSH session - if [ -z "$SSH_TTY" ] && type -p gpgconf > /dev/null 2>&1 + if [ -z "$SSH_TTY" ] && type gpgconf > /dev/null 2>&1 then unset SSH_AGENT_PID if [ "`gpgconf --list-dirs agent-ssh-socket | wc -l`" -eq 1 ] @@ -69,12 +69,12 @@ then fi fi -if [ "$VISUAL" == "vi" ] +if [ "$VISUAL" = "vi" ] then alias vim=vi fi -if type -p fortune > /dev/null 2>&1 && [ -z "$SSH_TTY" -a "$SHLVL" -le 1 -o \( -n "$DISPLAY" -a -z "$SSH_TTY" -a "$SHLVL" -le 2 \) ] +if type fortune > /dev/null 2>&1 && [ -z "$SSH_TTY" -a "$SHLVL" -le 1 -o \( -n "$DISPLAY" -a -z "$SSH_TTY" -a "$SHLVL" -le 2 \) ] then [ -n $NEWLINE ] && echo; unset NEWLINE fortune