From ef73a11e519b35f8138947e02fe67b73343d7505 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 07:33:28 +0200 Subject: [PATCH 1/8] Naive fixing of linter errors --- .config/shell/login.d/go.sh | 3 +- .config/shell/login.d/xdg.sh | 2 + .config/shell/rc.d/autostartx.sh | 8 +- .config/shell/rc.d/base-aliases.sh | 13 +- .../rc.d/dotfiles-version-control-commands.sh | 2 + .config/shell/rc.d/enable-fasd-hook.sh | 2 +- .config/shell/rc.d/fuzzy-finding.sh | 4 +- .config/shell/rc.d/set-locale-to-us-utf8.sh | 1 + .config/shell/rc.d/set-wiki-root.sh | 2 +- .../shell/rc.d/ssh-agent-autoconfiguration.sh | 285 +++++++++--------- .config/shell/rc.d/vifm-to-vm.sh | 4 +- .config/shell/zshrc.d/0-history.zsh | 7 +- .../shell/zshrc.d/0-inline-glob-expansion.zsh | 4 +- .config/shell/zshrc.d/0-plugins.zsh | 12 +- .../zshrc.d/0-screen-information-dialog.zsh | 7 +- .../1-enable-command-spelling-correction.zsh | 3 +- ...report-time-for-long-running-processes.zsh | 5 +- .../zshrc.d/1-set-up-powerlevel9k-theming.zsh | 2 + .../zshrc.d/5-install-tmux-plugin-manager.zsh | 8 +- .config/shell/zshrc.d/6-alias-l.zsh | 3 +- .config/shell/zshrc.d/6-mkcd.zsh | 3 +- .config/shell/zshrc.d/6-newest-files.zsh | 1 + .../shell/zshrc.d/6-ssht-tmux-attaching.zsh | 5 +- .../zshrc.d/9-configure-autocompletion.zsh | 2 +- .../zshrc.d/9-deduplicate-path-variable.zsh | 7 +- .../9-disable-enhancd-dot-dot-behavior.zsh | 1 + .../qutebrowser/userscripts/wallabag_add.sh | 5 - 27 files changed, 207 insertions(+), 194 deletions(-) diff --git a/.config/shell/login.d/go.sh b/.config/shell/login.d/go.sh index 2a96326..ccd4d33 100644 --- a/.config/shell/login.d/go.sh +++ b/.config/shell/login.d/go.sh @@ -1,3 +1,4 @@ -# //FIXME this needs to get the hell out of here -> put it in an env loading file +#!/bin/sh + export GOPATH="$HOME/projects/gopath/" export PATH="$PATH:$GOPATH/bin" diff --git a/.config/shell/login.d/xdg.sh b/.config/shell/login.d/xdg.sh index de86d61..3f7b276 100644 --- a/.config/shell/login.d/xdg.sh +++ b/.config/shell/login.d/xdg.sh @@ -1,3 +1,5 @@ +#!/bin/sh + # these are mandatory for the shell to work export XDG_CONFIG_HOME="$HOME/.config" export XDG_CACHE_HOME="$HOME/.cache" diff --git a/.config/shell/rc.d/autostartx.sh b/.config/shell/rc.d/autostartx.sh index 2296142..f598e0b 100644 --- a/.config/shell/rc.d/autostartx.sh +++ b/.config/shell/rc.d/autostartx.sh @@ -1,3 +1,5 @@ -# if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then -# exec startx ~/.xinitrc -# fi +#!/bin/sh + +if [ ! "$DISPLAY" ] && [ "$XDG_VTNR" -eq 1 ]; then + exec startx ~/.xinitrc +fi diff --git a/.config/shell/rc.d/base-aliases.sh b/.config/shell/rc.d/base-aliases.sh index 970cd4a..8f427ae 100644 --- a/.config/shell/rc.d/base-aliases.sh +++ b/.config/shell/rc.d/base-aliases.sh @@ -1,5 +1,7 @@ +#!/bin/sh + # Prettify ls commands -if [[ "$(uname -s)" == "Linux" ]]; then +if [ "$(uname -s)" = "Linux" ]; then # we're on linux alias l-d="ls -lFad" alias l="ls -lAhF" # Overwritten for k in -aliasing-k @@ -8,7 +10,10 @@ if [[ "$(uname -s)" == "Linux" ]]; then fi # Show the top 5 commands used in recent history -alias zhtop="history | awk '{a[\$2]++} END{for(i in a){printf \"%5d\t%s\n\",a[i],i}}' | sort -rn | head" +_zhtop() { + history | awk "{a[\$2]++} END{for(i in a){printf \"%5d\t%s\n\",a[i],i}}" | sort -rn | head +} +alias zhtop=_zhtop # Display timestamped recent command history alias zh="fc -l -d -D" @@ -28,5 +33,5 @@ alias cl="clear" # let me exit out of the shell same way as vim # TODO integrate session management with w? -alias ":q"="exit" -alias ":wq"="exit" +alias :q="exit" +alias :wq="exit" diff --git a/.config/shell/rc.d/dotfiles-version-control-commands.sh b/.config/shell/rc.d/dotfiles-version-control-commands.sh index e3c6852..a78aa3d 100644 --- a/.config/shell/rc.d/dotfiles-version-control-commands.sh +++ b/.config/shell/rc.d/dotfiles-version-control-commands.sh @@ -1,3 +1,5 @@ +#!/bin/sh + # enables git management through dot command alias dot='/usr/bin/git --git-dir=/home/marty/.dotfiles/ --work-tree=/home/marty' diff --git a/.config/shell/rc.d/enable-fasd-hook.sh b/.config/shell/rc.d/enable-fasd-hook.sh index 907fd96..4da3439 100644 --- a/.config/shell/rc.d/enable-fasd-hook.sh +++ b/.config/shell/rc.d/enable-fasd-hook.sh @@ -1,3 +1,3 @@ #!/bin/sh -# more usage instructions at https://github.com/clvv/fasd +# more usage instructions at https://github.com/clvv/fasd eval "$(fasd --init auto)" diff --git a/.config/shell/rc.d/fuzzy-finding.sh b/.config/shell/rc.d/fuzzy-finding.sh index 98ecd34..888beca 100644 --- a/.config/shell/rc.d/fuzzy-finding.sh +++ b/.config/shell/rc.d/fuzzy-finding.sh @@ -27,8 +27,8 @@ else fi # set up fuzzy file and directory search -alias f="fzf -c 'find . -type f' --preview='head -$LINES {}' | xargs xdg-open" -alias F="fzf -c 'find ~ -type f' --preview='head -$LINES {}' | xargs xdg-open" +alias f="fzf -c 'find . -type f' --preview='"'head -$LINES {}'"' | xargs xdg-open" +alias F="fzf -c 'find ~ -type f' --preview='"'head -$LINES {}'"' | xargs xdg-open" alias d="fzf -c 'find . -type d' --preview='ls --color='always' {}' | cd" alias D="fzf -c 'find ~ -type d' --preview='ls --color='always' {}' --color=dark --ansi | cd" diff --git a/.config/shell/rc.d/set-locale-to-us-utf8.sh b/.config/shell/rc.d/set-locale-to-us-utf8.sh index dfd829e..c0cfacb 100644 --- a/.config/shell/rc.d/set-locale-to-us-utf8.sh +++ b/.config/shell/rc.d/set-locale-to-us-utf8.sh @@ -1 +1,2 @@ export LC_ALL="en_US.utf-8" +export LANG="en_US.utf-8" diff --git a/.config/shell/rc.d/set-wiki-root.sh b/.config/shell/rc.d/set-wiki-root.sh index 3e9d535..25035fe 100644 --- a/.config/shell/rc.d/set-wiki-root.sh +++ b/.config/shell/rc.d/set-wiki-root.sh @@ -2,4 +2,4 @@ # set wiki root to nextcloud notes folder, # will be picked up by vim wiki plugin as root -export WIKIROOT='~/Nextcloud/Notes/' +export WIKIROOT="$HOME/Nextcloud/Notes/" diff --git a/.config/shell/rc.d/ssh-agent-autoconfiguration.sh b/.config/shell/rc.d/ssh-agent-autoconfiguration.sh index a8affb3..a95e020 100644 --- a/.config/shell/rc.d/ssh-agent-autoconfiguration.sh +++ b/.config/shell/rc.d/ssh-agent-autoconfiguration.sh @@ -1,3 +1,5 @@ +#!/bin/sh + ## Integration at the Bottom # Copyright (C) 2011 by Wayne Walker @@ -29,204 +31,189 @@ declare -a _LIVE_AGENT_SOCK_LIST _LIVE_AGENT_SOCK_LIST=() _debug_print() { - if [[ $_DEBUG -gt 0 ]] - then - printf "%s\n" $1 - fi + if [[ $_DEBUG -gt 0 ]]; then + printf "%s\n" $1 + fi } find_all_ssh_agent_sockets() { - _SSH_AGENT_SOCKETS=`find /tmp/ -type s -name agent.\* 2> /dev/null | grep '/tmp/ssh-.*/agent.*'` - _debug_print "$_SSH_AGENT_SOCKETS" + _SSH_AGENT_SOCKETS=$(find /tmp/ -type s -name agent.\* 2>/dev/null | grep '/tmp/ssh-.*/agent.*') + _debug_print "$_SSH_AGENT_SOCKETS" } find_all_gpg_agent_sockets() { - _GPG_AGENT_SOCKETS=`find /tmp/ -type s -name S.gpg-agent.ssh 2> /dev/null | grep '/tmp/gpg-.*/S.gpg-agent.ssh'` - _debug_print "$_GPG_AGENT_SOCKETS" + _GPG_AGENT_SOCKETS=$(find /tmp/ -type s -name S.gpg-agent.ssh 2>/dev/null | grep '/tmp/gpg-.*/S.gpg-agent.ssh') + _debug_print "$_GPG_AGENT_SOCKETS" } find_all_gnome_keyring_agent_sockets() { - _GNOME_KEYRING_AGENT_SOCKETS=`find /tmp/ -type s -name ssh 2> /dev/null | grep '/tmp/keyring-.*/ssh$'` - _debug_print "$_GNOME_KEYRING_AGENT_SOCKETS" + _GNOME_KEYRING_AGENT_SOCKETS=$(find /tmp/ -type s -name ssh 2>/dev/null | grep '/tmp/keyring-.*/ssh$') + _debug_print "$_GNOME_KEYRING_AGENT_SOCKETS" } find_all_osx_keychain_agent_sockets() { - [[ -n "$TMPDIR" ]] || TMPDIR=/tmp - _OSX_KEYCHAIN_AGENT_SOCKETS=`find $TMPDIR/ -type s -regex '.*/ssh-.*/agent..*$' 2> /dev/null` - _debug_print "$_OSX_KEYCHAIN_AGENT_SOCKETS" + [[ -n "$TMPDIR" ]] || TMPDIR=/tmp + _OSX_KEYCHAIN_AGENT_SOCKETS=$(find $TMPDIR/ -type s -regex '.*/ssh-.*/agent..*$' 2>/dev/null) + _debug_print "$_OSX_KEYCHAIN_AGENT_SOCKETS" } test_agent_socket() { - local SOCKET=$1 - SSH_AUTH_SOCK=$SOCKET ssh-add -l 2> /dev/null > /dev/null - result=$? + local SOCKET=$1 + SSH_AUTH_SOCK=$SOCKET ssh-add -l 2>/dev/null >/dev/null + result=$? - _debug_print $result + _debug_print $result - if [[ $result -eq 0 ]] - then - # contactible and has keys loaded - _KEY_COUNT=`SSH_AUTH_SOCK=$SOCKET ssh-add -l | wc -l | tr -d ' '` - fi + if [[ $result -eq 0 ]]; then + # contactible and has keys loaded + _KEY_COUNT=$(SSH_AUTH_SOCK=$SOCKET ssh-add -l | wc -l | tr -d ' ') + fi - if [[ $result -eq 1 ]] - then - # contactible butno keys loaded - _KEY_COUNT=0 - fi + if [[ $result -eq 1 ]]; then + # contactible butno keys loaded + _KEY_COUNT=0 + fi - if [[ ( ( $result -eq 0 ) || ( $result -eq 1 ) ) ]] - then - if [[ -n "$_LIVE_AGENT_LIST" ]] - then - _LIVE_AGENT_LIST="${_LIVE_AGENT_LIST} ${SOCKET}:$_KEY_COUNT" - else - _LIVE_AGENT_LIST="${SOCKET}:$_KEY_COUNT" - fi - return 0 - fi + if [[ (($result -eq 0) || ($result -eq 1)) ]]; then + if [[ -n "$_LIVE_AGENT_LIST" ]]; then + _LIVE_AGENT_LIST="${_LIVE_AGENT_LIST} ${SOCKET}:$_KEY_COUNT" + else + _LIVE_AGENT_LIST="${SOCKET}:$_KEY_COUNT" + fi + return 0 + fi - return 1 + return 1 } find_live_gnome_keyring_agents() { - for i in $_GNOME_KEYRING_AGENT_SOCKETS - do - test_agent_socket $i - done + for i in $_GNOME_KEYRING_AGENT_SOCKETS; do + test_agent_socket $i + done } find_live_osx_keychain_agents() { - for i in $_OSX_KEYCHAIN_AGENT_SOCKETS - do - test_agent_socket $i - done + for i in $_OSX_KEYCHAIN_AGENT_SOCKETS; do + test_agent_socket $i + done } find_live_gpg_agents() { - for i in $_GPG_AGENT_SOCKETS - do - test_agent_socket $i - done + for i in $_GPG_AGENT_SOCKETS; do + test_agent_socket $i + done } find_live_ssh_agents() { - for i in $_SSH_AGENT_SOCKETS - do - test_agent_socket $i - done + for i in $_SSH_AGENT_SOCKETS; do + test_agent_socket $i + done } function fingerprints() { - local file="$1" - while read l; do - [[ -n $l && ${l###} = $l ]] && ssh-keygen -l -f /dev/stdin <<<$l - done < $file + local file="$1" + while read l; do + [[ -n $l && ${l###} == $l ]] && ssh-keygen -l -f /dev/stdin <<<$l + done <$file } find_all_agent_sockets() { - _SHOW_IDENTITY=0 - if [ "$1" = "-i" ] ; then - _SHOW_IDENTITY=1 - fi - _LIVE_AGENT_LIST= - find_all_ssh_agent_sockets - find_all_gpg_agent_sockets - find_all_gnome_keyring_agent_sockets - find_all_osx_keychain_agent_sockets - find_live_ssh_agents - find_live_gpg_agents - find_live_gnome_keyring_agents - find_live_osx_keychain_agents - _debug_print "$_LIVE_AGENT_LIST" - _LIVE_AGENT_LIST=$(echo $_LIVE_AGENT_LIST | tr ' ' '\n' | sort -n -t: -k 2 -k 1 | uniq) - _LIVE_AGENT_SOCK_LIST=() - _debug_print "SORTED: $_LIVE_AGENT_LIST" - if [ -e ~/.ssh/authorized_keys ] ; then - _FINGERPRINTS=$(fingerprints ~/.ssh/authorized_keys) - fi - if [[ $_SHOW_IDENTITY -gt 0 ]] - then - i=0 - for a in $_LIVE_AGENT_LIST ; do - sock=${a/:*/} - _LIVE_AGENT_SOCK_LIST[$i]=$sock - # technically we could have multiple keys forwarded - # But I haven't seen anyone do it - akeys=$(SSH_AUTH_SOCK=$sock ssh-add -l) - key_size=$(echo ${akeys} | awk '{print $1}') - fingerprint=$(echo ${akeys} | awk '{print $2}') - remote_name=$(echo ${akeys} | awk '{print $3}') - if [ -e ~/.ssh/authorized_keys ] ; then - authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep $fingerprint) - fi - comment=$(echo ${authorized_entry} | awk '{print $3,$4,$5,$6,$7}') - printf "export SSH_AUTH_SOCK=%s \t#%i) \t%s\n" "$sock" $((i+1)) "$comment" - i=$((i+1)) - done - else - printf "%s\n" "$_LIVE_AGENT_LIST" | sed -e 's/ /\n/g' | sort -n -t: -k 2 -k 1 - fi + _SHOW_IDENTITY=0 + if [ "$1" = "-i" ]; then + _SHOW_IDENTITY=1 + fi + _LIVE_AGENT_LIST= + find_all_ssh_agent_sockets + find_all_gpg_agent_sockets + find_all_gnome_keyring_agent_sockets + find_all_osx_keychain_agent_sockets + find_live_ssh_agents + find_live_gpg_agents + find_live_gnome_keyring_agents + find_live_osx_keychain_agents + _debug_print "$_LIVE_AGENT_LIST" + _LIVE_AGENT_LIST=$(echo $_LIVE_AGENT_LIST | tr ' ' '\n' | sort -n -t: -k 2 -k 1 | uniq) + _LIVE_AGENT_SOCK_LIST=() + _debug_print "SORTED: $_LIVE_AGENT_LIST" + if [ -e ~/.ssh/authorized_keys ]; then + _FINGERPRINTS=$(fingerprints ~/.ssh/authorized_keys) + fi + if [[ $_SHOW_IDENTITY -gt 0 ]]; then + i=0 + for a in $_LIVE_AGENT_LIST; do + sock=${a/:*/} + _LIVE_AGENT_SOCK_LIST[$i]=$sock + # technically we could have multiple keys forwarded + # But I haven't seen anyone do it + akeys=$(SSH_AUTH_SOCK=$sock ssh-add -l) + key_size=$(echo ${akeys} | awk '{print $1}') + fingerprint=$(echo ${akeys} | awk '{print $2}') + remote_name=$(echo ${akeys} | awk '{print $3}') + if [ -e ~/.ssh/authorized_keys ]; then + authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep $fingerprint) + fi + comment=$(echo ${authorized_entry} | awk '{print $3,$4,$5,$6,$7}') + printf "export SSH_AUTH_SOCK=%s \t#%i) \t%s\n" "$sock" $((i + 1)) "$comment" + i=$((i + 1)) + done + else + printf "%s\n" "$_LIVE_AGENT_LIST" | sed -e 's/ /\n/g' | sort -n -t: -k 2 -k 1 + fi } set_ssh_agent_socket() { - if [ "$1" = "-c" -o "$1" = "--choose" ] - then - find_all_agent_sockets -i + if [ "$1" = "-c" -o "$1" = "--choose" ]; then + find_all_agent_sockets -i - if [ -z "$_LIVE_AGENT_LIST" ] ; then - echo "No agents found" - return 1 - fi + if [ -z "$_LIVE_AGENT_LIST" ]; then + echo "No agents found" + return 1 + fi - echo -n "Choose (1-${#_LIVE_AGENT_SOCK_LIST[@]})? " - read choice - if [ -n "$choice" ] - then - n=$((choice-1)) - if [ -z "${_LIVE_AGENT_SOCK_LIST[$n]}" ] ; then - echo "Invalid choice" - return 1 - fi - echo "Setting export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]}" - export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]} - fi - else - # Choose the first available - SOCK=$(find_all_agent_sockets|tail -n 1|awk -F: '{print $1}') - if [ -z "$SOCK" ] ; then - return 1 - fi - export SSH_AUTH_SOCK=$SOCK - fi + echo -n "Choose (1-${#_LIVE_AGENT_SOCK_LIST[@]})? " + read choice + if [ -n "$choice" ]; then + n=$((choice - 1)) + if [ -z "${_LIVE_AGENT_SOCK_LIST[$n]}" ]; then + echo "Invalid choice" + return 1 + fi + echo "Setting export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]}" + export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]} + fi + else + # Choose the first available + SOCK=$(find_all_agent_sockets | tail -n 1 | awk -F: '{print $1}') + if [ -z "$SOCK" ]; then + return 1 + fi + export SSH_AUTH_SOCK=$SOCK + fi - # set agent pid - if [ -n "$SSH_AUTH_SOCK" ] ; then - export SSH_AGENT_PID=$((`echo $SSH_AUTH_SOCK | cut -d. -f2` + 1)) - fi + # set agent pid + if [ -n "$SSH_AUTH_SOCK" ]; then + export SSH_AGENT_PID=$(($(echo $SSH_AUTH_SOCK | cut -d. -f2) + 1)) + fi - return 0 + return 0 } ssh-find-agent() { - if [ "$1" = "-c" -o "$1" = "--choose" ] - then - set_ssh_agent_socket -c - return $? - elif [ "$1" = "-a" -o "$1" = "--auto" ] - then - set_ssh_agent_socket - return $? - else - find_all_agent_sockets -i - return 0 - fi + if [ "$1" = "-c" -o "$1" = "--choose" ]; then + set_ssh_agent_socket -c + return $? + elif [ "$1" = "-a" -o "$1" = "--auto" ]; then + set_ssh_agent_socket + return $? + else + find_all_agent_sockets -i + return 0 + fi } # Automatically add ssh-agent to any new ssh connection ssh-find-agent -a -if [ -z "$SSH_AUTH_SOCK" ] -then - eval $(ssh-agent) > /dev/null - ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' -fi \ No newline at end of file +if [ -z "$SSH_AUTH_SOCK" ]; then + eval $(ssh-agent) >/dev/null + ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' +fi diff --git a/.config/shell/rc.d/vifm-to-vm.sh b/.config/shell/rc.d/vifm-to-vm.sh index 7e5ece2..5fd5f0d 100644 --- a/.config/shell/rc.d/vifm-to-vm.sh +++ b/.config/shell/rc.d/vifm-to-vm.sh @@ -4,9 +4,7 @@ type vifm >/dev/null 2>&1 && alias vm=vifm # if vifm exists, also let me open current dir in vifm with vmm -type vifm >/dev/null 2>&1 && alias vmm="vifm ${PWD}" +type vifm >/dev/null 2>&1 && alias vmm='vifm ${PWD}' # Check for existence of vifmrun command. If found, substitute vifm with it. type vifmrun >/dev/null 2>&1 && alias vifm=vifmrun - - diff --git a/.config/shell/zshrc.d/0-history.zsh b/.config/shell/zshrc.d/0-history.zsh index 4444450..00f3154 100644 --- a/.config/shell/zshrc.d/0-history.zsh +++ b/.config/shell/zshrc.d/0-history.zsh @@ -1,3 +1,5 @@ +#!/bin/zsh + ### Set ZSH History defaults # set some history options @@ -20,8 +22,7 @@ setopt pushd_ignore_dups #setopt pushd_silent # Keep a ton of history. -HISTSIZE=100000 -SAVEHIST=100000 +export HISTSIZE=100000 +export SAVEHIST=100000 HISTFILE=~/.zsh_history export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help" - diff --git a/.config/shell/zshrc.d/0-inline-glob-expansion.zsh b/.config/shell/zshrc.d/0-inline-glob-expansion.zsh index c9fdcac..94d697b 100644 --- a/.config/shell/zshrc.d/0-inline-glob-expansion.zsh +++ b/.config/shell/zshrc.d/0-inline-glob-expansion.zsh @@ -1,6 +1,8 @@ +#!/bin/zsh +# # Expand aliases inline - see http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html globalias() { - if [[ $LBUFFER =~ ' [A-Z0-9]+$' ]]; then + if [[ $LBUFFER =~ [A-Z0-9]+$ ]]; then zle _expand_alias zle expand-word fi diff --git a/.config/shell/zshrc.d/0-plugins.zsh b/.config/shell/zshrc.d/0-plugins.zsh index a674d92..3539034 100644 --- a/.config/shell/zshrc.d/0-plugins.zsh +++ b/.config/shell/zshrc.d/0-plugins.zsh @@ -1,3 +1,4 @@ +#!/bin/zsh # Clone zgen if you haven't already check_zgen_installation() { if [[ -z "$ZGEN_PARENT_DIR" ]]; then @@ -8,10 +9,11 @@ check_zgen_installation() { if [[ ! -d "$ZGEN_PARENT_DIR" ]]; then mkdir -p "$ZGEN_PARENT_DIR" fi - pushd $ZGEN_PARENT_DIR + cd $ZGEN_PARENT_DIR || return git clone https://github.com/tarjoilija/zgen.git $ZGEN_DIR - popd fi + # shellcheck source=/home/marty/.config/zgen/zgen.zsh + # shellcheck disable=SC1091 source $ZGEN_DIR/zgen.zsh unset ZGEN_PARENT_DIR } @@ -34,8 +36,8 @@ load_plugins() { # Set keystrokes for substring searching zmodload zsh/terminfo - bindkey "$terminfo[kcuu1]" history-substring-search-up - bindkey "$terminfo[kcud1]" history-substring-search-down + bindkey "${terminfo[kcuu1]:?}" history-substring-search-up + bindkey "${terminfo[kcud1]:?}" history-substring-search-down # Automatically run zgen update and zgen selfupdate every 7 days. zgen load unixorn/autoupdate-zgen @@ -91,7 +93,7 @@ load_plugins() { zgen oh-my-zsh plugins/screen zgen oh-my-zsh plugins/vagrant # check for autojump install before applying plugin - if [ type autojump >/dev/null 2>&1 ]; then + if type autojump >/dev/null 2>&1; then zgen oh-my-zsh plugins/autojump fi zgen oh-my-zsh plugins/tmux diff --git a/.config/shell/zshrc.d/0-screen-information-dialog.zsh b/.config/shell/zshrc.d/0-screen-information-dialog.zsh index 14bf909..a51b071 100644 --- a/.config/shell/zshrc.d/0-screen-information-dialog.zsh +++ b/.config/shell/zshrc.d/0-screen-information-dialog.zsh @@ -1,11 +1,12 @@ +#!/bin/zsh # deal with screen, if we're using it - courtesy MacOSXHints.com # Login greeting ------------------ -if [ "$TERM" = "screen" -a ! "$SHOWED_SCREEN_MESSAGE" = "true" ]; then +if [ "$TERM" = "screen" ] && [ ! "$SHOWED_SCREEN_MESSAGE" = "true" ]; then detached_screens=$(screen -list | grep Detached) - if [ ! -z "$detached_screens" ]; then + if [ -n "$detached_screens" ]; then echo "+---------------------------------------+" echo "| Detached screens are available: |" echo "$detached_screens" echo "+---------------------------------------+" fi -fi \ No newline at end of file +fi diff --git a/.config/shell/zshrc.d/1-enable-command-spelling-correction.zsh b/.config/shell/zshrc.d/1-enable-command-spelling-correction.zsh index 3974cf2..ad02c1b 100644 --- a/.config/shell/zshrc.d/1-enable-command-spelling-correction.zsh +++ b/.config/shell/zshrc.d/1-enable-command-spelling-correction.zsh @@ -1,3 +1,4 @@ +#!/bin/zsh # Correct spelling for commands setopt correct @@ -8,4 +9,4 @@ unsetopt correctall ENABLE_CORRECTION="true" # Display red dots whilst waiting for completion. -COMPLETION_WAITING_DOTS="true" \ No newline at end of file +COMPLETION_WAITING_DOTS="true" diff --git a/.config/shell/zshrc.d/1-report-time-for-long-running-processes.zsh b/.config/shell/zshrc.d/1-report-time-for-long-running-processes.zsh index 82fe4e4..bf16597 100644 --- a/.config/shell/zshrc.d/1-report-time-for-long-running-processes.zsh +++ b/.config/shell/zshrc.d/1-report-time-for-long-running-processes.zsh @@ -1,4 +1,5 @@ +#!/bin/zsh # Long running processes should return time after they complete. Specified # in seconds. -REPORTTIME=2 -TIMEFMT="%U user %S system %P cpu %*Es total" +export REPORTTIME=2 +export TIMEFMT="%U user %S system %P cpu %*Es total" diff --git a/.config/shell/zshrc.d/1-set-up-powerlevel9k-theming.zsh b/.config/shell/zshrc.d/1-set-up-powerlevel9k-theming.zsh index 38b65ee..9716353 100644 --- a/.config/shell/zshrc.d/1-set-up-powerlevel9k-theming.zsh +++ b/.config/shell/zshrc.d/1-set-up-powerlevel9k-theming.zsh @@ -1,3 +1,5 @@ +#!/bin/zsh + POWERLEVEL9K_MODE='nerdfont-complete' #POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 #POWERLEVEL9K_SHORTEN_DELIMITER="" diff --git a/.config/shell/zshrc.d/5-install-tmux-plugin-manager.zsh b/.config/shell/zshrc.d/5-install-tmux-plugin-manager.zsh index 8452097..31d67d0 100644 --- a/.config/shell/zshrc.d/5-install-tmux-plugin-manager.zsh +++ b/.config/shell/zshrc.d/5-install-tmux-plugin-manager.zsh @@ -1,3 +1,5 @@ +#!/bin/zsh +# # Clone tmux plugin manager if not existing if [[ -z "$TPM_PARENT_DIR" ]]; then TPM_PARENT_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/tmux @@ -7,14 +9,12 @@ if [[ ! -f $TPM_PARENT_DIR/plugins/tpm/tpm ]]; then if [[ ! -d "$TPM_PARENT_DIR" ]]; then mkdir -p "$TPM_PARENT_DIR" fi - pushd $TPM_PARENT_DIR + cd "$TPM_PARENT_DIR" || exit git clone https://github.com/tmux-plugins/tpm plugins/tpm - popd fi export TMUX_PLUGIN_MANAGER_PATH=$TPM_PARENT_DIR/plugins -alias tmux="tmux -f ${TPM_PARENT_DIR}/tmux.conf" +alias tmux="tmux -f "'"${TPM_PARENT_DIR}"'"/tmux.conf" unset TPM_PARENT_DIR unset TPM_SUB_DIR - diff --git a/.config/shell/zshrc.d/6-alias-l.zsh b/.config/shell/zshrc.d/6-alias-l.zsh index 1085a51..2e66b7a 100644 --- a/.config/shell/zshrc.d/6-alias-l.zsh +++ b/.config/shell/zshrc.d/6-alias-l.zsh @@ -1,3 +1,4 @@ +#!/bin/zsh # uses k (installed with plugins) but makes it accessible through l as well alias k="k -h" -alias l="k -A" \ No newline at end of file +alias l="k -A" diff --git a/.config/shell/zshrc.d/6-mkcd.zsh b/.config/shell/zshrc.d/6-mkcd.zsh index f1e39fd..f2e8a49 100644 --- a/.config/shell/zshrc.d/6-mkcd.zsh +++ b/.config/shell/zshrc.d/6-mkcd.zsh @@ -1,4 +1,5 @@ +#!/bin/zsh # mkdir & cd function mkcd { - mkdir -p "$@" && cd $_ + mkdir -p "$@" && cd "$_" || return } diff --git a/.config/shell/zshrc.d/6-newest-files.zsh b/.config/shell/zshrc.d/6-newest-files.zsh index 79d609c..6c6c3a1 100644 --- a/.config/shell/zshrc.d/6-newest-files.zsh +++ b/.config/shell/zshrc.d/6-newest-files.zsh @@ -1,3 +1,4 @@ +#!/bin/zsh # show newest files # http://www.commandlinefu.com/commands/view/9015/find-the-most-recently-changed-files-recursively newest (){ diff --git a/.config/shell/zshrc.d/6-ssht-tmux-attaching.zsh b/.config/shell/zshrc.d/6-ssht-tmux-attaching.zsh index a122299..7ceb6ff 100644 --- a/.config/shell/zshrc.d/6-ssht-tmux-attaching.zsh +++ b/.config/shell/zshrc.d/6-ssht-tmux-attaching.zsh @@ -1,5 +1,6 @@ +#!/bin/zsh # automatically use tmux whenever we ssh to a server function ssht(){ - ssh $* -t 'tmux a || tmux || /bin/bash' -} \ No newline at end of file + ssh "$@" -t 'tmux a || tmux || /bin/bash' +} diff --git a/.config/shell/zshrc.d/9-configure-autocompletion.zsh b/.config/shell/zshrc.d/9-configure-autocompletion.zsh index 9be9736..8fe1134 100644 --- a/.config/shell/zshrc.d/9-configure-autocompletion.zsh +++ b/.config/shell/zshrc.d/9-configure-autocompletion.zsh @@ -10,4 +10,4 @@ if [ -d ~/.zsh-completions ]; then do source "$completion" done -fi \ No newline at end of file +fi diff --git a/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh b/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh index 15f4082..3f2cfe4 100644 --- a/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh +++ b/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh @@ -1,3 +1,8 @@ +#!/bin/zsh +# shellcheck disable=SC2206 +# shellcheck disable=SC2179 +# shellcheck disable=SC2154 + # In case a plugin adds a redundant path entry, remove duplicate entries # from PATH # @@ -16,4 +21,4 @@ dedupe_path() { export PATH=${(j+:+)result} } -dedupe_path \ No newline at end of file +dedupe_path diff --git a/.config/shell/zshrc.d/9-disable-enhancd-dot-dot-behavior.zsh b/.config/shell/zshrc.d/9-disable-enhancd-dot-dot-behavior.zsh index 5ff2815..87fcf5c 100644 --- a/.config/shell/zshrc.d/9-disable-enhancd-dot-dot-behavior.zsh +++ b/.config/shell/zshrc.d/9-disable-enhancd-dot-dot-behavior.zsh @@ -1,3 +1,4 @@ +#!/bin/zsh # Assumes enhancd is installed (via plugin) # Let's you go back a directory with .. (usual cd .. behavior) # Let's the enhancd backtrack menu appear with cd .. (usual enhancd behavior) diff --git a/.local/share/qutebrowser/userscripts/wallabag_add.sh b/.local/share/qutebrowser/userscripts/wallabag_add.sh index ab4c707..2b6cb33 100755 --- a/.local/share/qutebrowser/userscripts/wallabag_add.sh +++ b/.local/share/qutebrowser/userscripts/wallabag_add.sh @@ -3,10 +3,5 @@ # from swalladge: # https://github.com/swalladge/dotfiles/blob/master/local/share/qutebrowser/userscripts/wallabag_add.sh -# for wallabag v1.* -# `-w 0` disables auto line wrapping in base64 -# echo "open -t https://www.framabag.org/u/swalladge/?action=add&url='`echo -n "$QUTE_URL" | base64 -w 0`'" >> "$QUTE_FIFO" - - # v2.* echo "open https://read.martyoeh.me/bookmarklet?url=$QUTE_URL" >> "$QUTE_FIFO" From 05c189cfa4902de3d47ebef91cc8d91109ff461e Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 10:42:12 +0200 Subject: [PATCH 2/8] Fix merge errors --- .config/shell/rc.d/fuzzy-finding.sh | 4 ++-- .local/share/qutebrowser/userscripts/wallabag_add.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.config/shell/rc.d/fuzzy-finding.sh b/.config/shell/rc.d/fuzzy-finding.sh index 888beca..988f5b5 100644 --- a/.config/shell/rc.d/fuzzy-finding.sh +++ b/.config/shell/rc.d/fuzzy-finding.sh @@ -27,8 +27,8 @@ else fi # set up fuzzy file and directory search -alias f="fzf -c 'find . -type f' --preview='"'head -$LINES {}'"' | xargs xdg-open" -alias F="fzf -c 'find ~ -type f' --preview='"'head -$LINES {}'"' | xargs xdg-open" +alias f="fzf -c 'find . -type f' --preview='"'head -$LINES {}'"' | xargs -0 xdg-open" +alias F="fzf -c 'find ~ -type f' --preview='"'head -$LINES {}'"' | xargs -0 xdg-open" alias d="fzf -c 'find . -type d' --preview='ls --color='always' {}' | cd" alias D="fzf -c 'find ~ -type d' --preview='ls --color='always' {}' --color=dark --ansi | cd" diff --git a/.local/share/qutebrowser/userscripts/wallabag_add.sh b/.local/share/qutebrowser/userscripts/wallabag_add.sh index 2b6cb33..7b04ff3 100755 --- a/.local/share/qutebrowser/userscripts/wallabag_add.sh +++ b/.local/share/qutebrowser/userscripts/wallabag_add.sh @@ -4,4 +4,4 @@ # https://github.com/swalladge/dotfiles/blob/master/local/share/qutebrowser/userscripts/wallabag_add.sh # v2.* -echo "open https://read.martyoeh.me/bookmarklet?url=$QUTE_URL" >> "$QUTE_FIFO" +echo "open https://read.martyoeh.me/bookmarklet?url=$QUTE_URL" >>"$QUTE_FIFO" From bedf7e18a904c00b3049c9ffe02a84c5dbc299ec Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 10:54:06 +0200 Subject: [PATCH 3/8] Fix static analysis errors --- .config/shell/login.d/dotfilescripts.sh | 5 ++- .config/shell/rc.d/set-locale-to-us-utf8.sh | 2 + .../shell/rc.d/ssh-agent-autoconfiguration.sh | 43 ++++++++----------- .../zshrc.d/9-configure-autocompletion.zsh | 2 + 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/.config/shell/login.d/dotfilescripts.sh b/.config/shell/login.d/dotfilescripts.sh index e0586ea..b4f165c 100644 --- a/.config/shell/login.d/dotfilescripts.sh +++ b/.config/shell/login.d/dotfilescripts.sh @@ -1,2 +1,5 @@ +#!/bin/sh + # put personal scripts on the PATH to be callable -export PATH="$(du $HOME/.local/bin | cut -f2 | tr '\n' ':')$PATH" +PATH=$(du "$HOME"/.local/bin | cut -f2 | tr '\n' ':')$PATH +export PATH diff --git a/.config/shell/rc.d/set-locale-to-us-utf8.sh b/.config/shell/rc.d/set-locale-to-us-utf8.sh index c0cfacb..68c9d97 100644 --- a/.config/shell/rc.d/set-locale-to-us-utf8.sh +++ b/.config/shell/rc.d/set-locale-to-us-utf8.sh @@ -1,2 +1,4 @@ +#!/bin/sh + export LC_ALL="en_US.utf-8" export LANG="en_US.utf-8" diff --git a/.config/shell/rc.d/ssh-agent-autoconfiguration.sh b/.config/shell/rc.d/ssh-agent-autoconfiguration.sh index a95e020..d571489 100644 --- a/.config/shell/rc.d/ssh-agent-autoconfiguration.sh +++ b/.config/shell/rc.d/ssh-agent-autoconfiguration.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ## Integration at the Bottom @@ -32,7 +32,7 @@ _LIVE_AGENT_SOCK_LIST=() _debug_print() { if [[ $_DEBUG -gt 0 ]]; then - printf "%s\n" $1 + printf "%s\n" "$1" fi } @@ -47,7 +47,7 @@ find_all_gpg_agent_sockets() { } find_all_gnome_keyring_agent_sockets() { - _GNOME_KEYRING_AGENT_SOCKETS=$(find /tmp/ -type s -name ssh 2>/dev/null | grep '/tmp/keyring-.*/ssh$') + _GNOME_KEYRING_AGENT_SOCKETS=$(find /tmp/ -type s -name "ssh" 2>/dev/null | grep '/tmp/keyring-.*/ssh$') _debug_print "$_GNOME_KEYRING_AGENT_SOCKETS" } @@ -88,33 +88,33 @@ test_agent_socket() { find_live_gnome_keyring_agents() { for i in $_GNOME_KEYRING_AGENT_SOCKETS; do - test_agent_socket $i + test_agent_socket "$i" done } find_live_osx_keychain_agents() { for i in $_OSX_KEYCHAIN_AGENT_SOCKETS; do - test_agent_socket $i + test_agent_socket "$i" done } find_live_gpg_agents() { for i in $_GPG_AGENT_SOCKETS; do - test_agent_socket $i + test_agent_socket "$i" done } find_live_ssh_agents() { for i in $_SSH_AGENT_SOCKETS; do - test_agent_socket $i + test_agent_socket "$i" done } function fingerprints() { local file="$1" - while read l; do - [[ -n $l && ${l###} == $l ]] && ssh-keygen -l -f /dev/stdin <<<$l - done <$file + while read -r l; do + [[ -n $l && ${l###} == "$l" ]] && ssh-keygen -l -f /dev/stdin <<<"$l" + done <"$file" } find_all_agent_sockets() { @@ -135,9 +135,6 @@ find_all_agent_sockets() { _LIVE_AGENT_LIST=$(echo $_LIVE_AGENT_LIST | tr ' ' '\n' | sort -n -t: -k 2 -k 1 | uniq) _LIVE_AGENT_SOCK_LIST=() _debug_print "SORTED: $_LIVE_AGENT_LIST" - if [ -e ~/.ssh/authorized_keys ]; then - _FINGERPRINTS=$(fingerprints ~/.ssh/authorized_keys) - fi if [[ $_SHOW_IDENTITY -gt 0 ]]; then i=0 for a in $_LIVE_AGENT_LIST; do @@ -146,13 +143,11 @@ find_all_agent_sockets() { # technically we could have multiple keys forwarded # But I haven't seen anyone do it akeys=$(SSH_AUTH_SOCK=$sock ssh-add -l) - key_size=$(echo ${akeys} | awk '{print $1}') - fingerprint=$(echo ${akeys} | awk '{print $2}') - remote_name=$(echo ${akeys} | awk '{print $3}') + fingerprint=$(echo "${akeys}" | awk '{print $2}') if [ -e ~/.ssh/authorized_keys ]; then - authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep $fingerprint) + authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep "$fingerprint") fi - comment=$(echo ${authorized_entry} | awk '{print $3,$4,$5,$6,$7}') + comment=$(echo "${authorized_entry}" | awk '{print $3,$4,$5,$6,$7}') printf "export SSH_AUTH_SOCK=%s \t#%i) \t%s\n" "$sock" $((i + 1)) "$comment" i=$((i + 1)) done @@ -162,7 +157,7 @@ find_all_agent_sockets() { } set_ssh_agent_socket() { - if [ "$1" = "-c" -o "$1" = "--choose" ]; then + if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then find_all_agent_sockets -i if [ -z "$_LIVE_AGENT_LIST" ]; then @@ -171,7 +166,7 @@ set_ssh_agent_socket() { fi echo -n "Choose (1-${#_LIVE_AGENT_SOCK_LIST[@]})? " - read choice + read -r choice if [ -n "$choice" ]; then n=$((choice - 1)) if [ -z "${_LIVE_AGENT_SOCK_LIST[$n]}" ]; then @@ -192,17 +187,17 @@ set_ssh_agent_socket() { # set agent pid if [ -n "$SSH_AUTH_SOCK" ]; then - export SSH_AGENT_PID=$(($(echo $SSH_AUTH_SOCK | cut -d. -f2) + 1)) + export SSH_AGENT_PID=$(($(echo "$SSH_AUTH_SOCK" | cut -d. -f2) + 1)) fi return 0 } ssh-find-agent() { - if [ "$1" = "-c" -o "$1" = "--choose" ]; then + if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then set_ssh_agent_socket -c return $? - elif [ "$1" = "-a" -o "$1" = "--auto" ]; then + elif [ "$1" = "-a" ] || [ "$1" = "--auto" ]; then set_ssh_agent_socket return $? else @@ -214,6 +209,6 @@ ssh-find-agent() { # Automatically add ssh-agent to any new ssh connection ssh-find-agent -a if [ -z "$SSH_AUTH_SOCK" ]; then - eval $(ssh-agent) >/dev/null + eval "$(ssh-agent)" >/dev/null ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' fi diff --git a/.config/shell/zshrc.d/9-configure-autocompletion.zsh b/.config/shell/zshrc.d/9-configure-autocompletion.zsh index 8fe1134..7fb3ebf 100644 --- a/.config/shell/zshrc.d/9-configure-autocompletion.zsh +++ b/.config/shell/zshrc.d/9-configure-autocompletion.zsh @@ -2,12 +2,14 @@ zstyle ':completion:*' accept-exact '*(N)' zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.zsh/cache +# shellcheck disable=SC2016 zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")'; # Load any custom zsh completions we've installed if [ -d ~/.zsh-completions ]; then for completion in ~/.zsh-completions/* do + # shellcheck source=/dev/null source "$completion" done fi From bf231783142af24f7e63e8bf5a00af6d95f63ad9 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 10:55:01 +0200 Subject: [PATCH 4/8] [gitlab] Let shellcheck choose sh version --- .gitlab-ci.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 583c737..ddeb2a6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,17 +5,17 @@ # you can delete this line if you're not using Docker image: fnichol/check-shell:latest -shellcheck: +analyze: stage: test before_script: - shellcheck --version script: - echo "--------- CHECKING POSIX SHELLSCRIPTS -------------" - - find . -type f -name '*.sh' | xargs shellcheck -s sh + - find . -type f -name '*.sh' | xargs shellcheck - echo "--------- CHECKING ZSH SHELLSCRIPTS -------------" - - find . -type f -name '*.zsh' | xargs shellcheck -s bash + - find . -type f -name '*.zsh' | xargs shellcheck -s bash -e SC2034 -shfmt: +lint: stage: test before_script: - shfmt -version @@ -24,3 +24,11 @@ shfmt: - find . -type f -name '*.sh' | xargs shfmt -d -i 2 - echo "--------- CHECKING ZSH SHELLSCRIPTS -------------" - find . -type f -name '*.zsh' | xargs shfmt -d -i 2 + +test: + stage: test + image: bats/bats:latest + before_script: + - bats --version + script: + - bats -r . From 8494eda973579b9dbff20a365f0d6f1bcd6de083 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 10:58:46 +0200 Subject: [PATCH 5/8] [nvim] Add shfmt and analysis to zsh files --- .config/nvim/init.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 5a7e877..4391256 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -274,11 +274,13 @@ let g:ale_fixers = { \'*': ['remove_trailing_lines', 'trim_whitespace'], \'go': ['gofmt'], \'sh': ['shfmt'], + \'zsh': ['shfmt'], \} let g:ale_linters = { \ 'go': ['gopls'], \ 'sh': ['language_server','shellcheck'], + \ 'zsh': ['language_server','shellcheck'], \} " PLUGIN: AIRLINE From d7e883142301e1454d5d36ff359f6c33bc5e0438 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 11:32:04 +0200 Subject: [PATCH 6/8] Fix static analysis and lint errors --- .../shell/rc.d/ssh-agent-autoconfiguration.sh | 2 +- .../shell/zshrc.d/0-inline-glob-expansion.zsh | 10 +- .config/shell/zshrc.d/0-plugins.zsh | 164 +++++++++--------- .../zshrc.d/1-set-up-powerlevel9k-theming.zsh | 2 +- .config/shell/zshrc.d/6-mkcd.zsh | 4 +- .config/shell/zshrc.d/6-newest-files.zsh | 12 +- .../shell/zshrc.d/6-ssht-tmux-attaching.zsh | 2 +- .../zshrc.d/9-configure-autocompletion.zsh | 7 +- .../zshrc.d/9-deduplicate-path-variable.zsh | 30 ++-- 9 files changed, 116 insertions(+), 117 deletions(-) diff --git a/.config/shell/rc.d/ssh-agent-autoconfiguration.sh b/.config/shell/rc.d/ssh-agent-autoconfiguration.sh index d571489..ed271b5 100644 --- a/.config/shell/rc.d/ssh-agent-autoconfiguration.sh +++ b/.config/shell/rc.d/ssh-agent-autoconfiguration.sh @@ -74,7 +74,7 @@ test_agent_socket() { _KEY_COUNT=0 fi - if [[ (($result -eq 0) || ($result -eq 1)) ]]; then + if [ $result -eq 0 ] || [ $result -eq 1 ]; then if [[ -n "$_LIVE_AGENT_LIST" ]]; then _LIVE_AGENT_LIST="${_LIVE_AGENT_LIST} ${SOCKET}:$_KEY_COUNT" else diff --git a/.config/shell/zshrc.d/0-inline-glob-expansion.zsh b/.config/shell/zshrc.d/0-inline-glob-expansion.zsh index 94d697b..c18d7db 100644 --- a/.config/shell/zshrc.d/0-inline-glob-expansion.zsh +++ b/.config/shell/zshrc.d/0-inline-glob-expansion.zsh @@ -2,11 +2,11 @@ # # Expand aliases inline - see http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html globalias() { - if [[ $LBUFFER =~ [A-Z0-9]+$ ]]; then - zle _expand_alias - zle expand-word - fi - zle self-insert + if [[ $LBUFFER =~ [A-Z0-9]+$ ]]; then + zle _expand_alias + zle expand-word + fi + zle self-insert } zle -N globalias diff --git a/.config/shell/zshrc.d/0-plugins.zsh b/.config/shell/zshrc.d/0-plugins.zsh index 3539034..33135e6 100644 --- a/.config/shell/zshrc.d/0-plugins.zsh +++ b/.config/shell/zshrc.d/0-plugins.zsh @@ -2,127 +2,127 @@ # Clone zgen if you haven't already check_zgen_installation() { if [[ -z "$ZGEN_PARENT_DIR" ]]; then - ZGEN_PARENT_DIR=${${XDG_CONFIG_HOME}:="$HOME/.config/"} + ZGEN_PARENT_DIR=${XDG_CONFIG_HOME:="$HOME/.config/"} ZGEN_DIR="$ZGEN_PARENT_DIR/zgen" fi if [[ ! -f $ZGEN_DIR/zgen.zsh ]]; then if [[ ! -d "$ZGEN_PARENT_DIR" ]]; then mkdir -p "$ZGEN_PARENT_DIR" fi - cd $ZGEN_PARENT_DIR || return - git clone https://github.com/tarjoilija/zgen.git $ZGEN_DIR + cd "$ZGEN_PARENT_DIR" || return + git clone https://github.com/tarjoilija/zgen.git "$ZGEN_DIR" fi # shellcheck source=/home/marty/.config/zgen/zgen.zsh # shellcheck disable=SC1091 - source $ZGEN_DIR/zgen.zsh + source "$ZGEN_DIR"/zgen.zsh unset ZGEN_PARENT_DIR } load_plugins() { - ZGEN_LOADED=() - ZGEN_COMPLETIONS=() + ZGEN_LOADED=() + ZGEN_COMPLETIONS=() - zgen oh-my-zsh + zgen oh-my-zsh - # If you want to customize your plugin list, create a file named - # .zgen-local-plugins in your home directory. That file will be sourced - # during startup *instead* of running this load-starter-plugin-list function, - # so make sure to include everything from this function that you want to keep. + # If you want to customize your plugin list, create a file named + # .zgen-local-plugins in your home directory. That file will be sourced + # during startup *instead* of running this load-starter-plugin-list function, + # so make sure to include everything from this function that you want to keep. - # If zsh-syntax-highlighting is bundled after zsh-history-substring-search, - # they break, so get the order right. - zgen load zdharma/fast-syntax-highlighting - zgen load zsh-users/zsh-history-substring-search + # If zsh-syntax-highlighting is bundled after zsh-history-substring-search, + # they break, so get the order right. + zgen load zdharma/fast-syntax-highlighting + zgen load zsh-users/zsh-history-substring-search - # Set keystrokes for substring searching - zmodload zsh/terminfo - bindkey "${terminfo[kcuu1]:?}" history-substring-search-up - bindkey "${terminfo[kcud1]:?}" history-substring-search-down + # Set keystrokes for substring searching + zmodload zsh/terminfo + bindkey "${terminfo[kcuu1]:?}" history-substring-search-up + bindkey "${terminfo[kcud1]:?}" history-substring-search-down - # Automatically run zgen update and zgen selfupdate every 7 days. - zgen load unixorn/autoupdate-zgen + # Automatically run zgen update and zgen selfupdate every 7 days. + zgen load unixorn/autoupdate-zgen - # Warn you when you run a command that you've set an alias for without - # using the alias. - zgen load djui/alias-tips + # Warn you when you run a command that you've set an alias for without + # using the alias. + zgen load djui/alias-tips - # Colorize the things if you have grc installed. Well, some of the - # things, anyway. - zgen load unixorn/warhol.plugin.zsh + # Colorize the things if you have grc installed. Well, some of the + # things, anyway. + zgen load unixorn/warhol.plugin.zsh - zgen load chrissicool/zsh-256color + zgen load chrissicool/zsh-256color - # Add Fish-like autosuggestions to your ZSH. - zgen load zsh-users/zsh-autosuggestions + # Add Fish-like autosuggestions to your ZSH. + zgen load zsh-users/zsh-autosuggestions - # k is a zsh script / plugin to make directory listings more readable, - # adding a bit of color and some git status information on files and - # directories. - zgen load supercrabtree/k + # k is a zsh script / plugin to make directory listings more readable, + # adding a bit of color and some git status information on files and + # directories. + zgen load supercrabtree/k - # Bullet train prompt setup. - zgen load bhilburn/powerlevel9k powerlevel9k + # Bullet train prompt setup. + zgen load bhilburn/powerlevel9k powerlevel9k - # automatically sources (known/whitelisted) .autoenv.zsh files - # as long as you're in the folder (and can optionally 'unsource' on leaving) - zgen load Tarrasch/zsh-autoenv + # automatically sources (known/whitelisted) .autoenv.zsh files + # as long as you're in the folder (and can optionally 'unsource' on leaving) + zgen load Tarrasch/zsh-autoenv - # radically enhanced cd command, all sorts of options - zgen load b4b4r07/enhancd + # radically enhanced cd command, all sorts of options + zgen load b4b4r07/enhancd - # set up nvm, the npm version manager - zgen load lukechilds/zsh-nvm + # set up nvm, the npm version manager + zgen load lukechilds/zsh-nvm - # Add git helper scripts. - zgen load unixorn/git-extra-commands + # Add git helper scripts. + zgen load unixorn/git-extra-commands - # Tom Limoncelli's tooling for storing private information (keys, etc) - # in a repository securely by encrypting them with gnupg. - zgen load StackExchange/blackbox + # Tom Limoncelli's tooling for storing private information (keys, etc) + # in a repository securely by encrypting them with gnupg. + zgen load StackExchange/blackbox - # Load some oh-my-zsh plugins - zgen oh-my-zsh plugins/pip - zgen oh-my-zsh plugins/sudo - zgen oh-my-zsh plugins/aws - zgen oh-my-zsh plugins/chruby - zgen oh-my-zsh plugins/colored-man-pages - zgen oh-my-zsh plugins/git - zgen oh-my-zsh plugins/github - zgen oh-my-zsh plugins/python - zgen oh-my-zsh plugins/rsync - zgen oh-my-zsh plugins/screen - zgen oh-my-zsh plugins/vagrant - # check for autojump install before applying plugin - if type autojump >/dev/null 2>&1; then - zgen oh-my-zsh plugins/autojump - fi - zgen oh-my-zsh plugins/tmux - zgen oh-my-zsh plugins/tmuxinator + # Load some oh-my-zsh plugins + zgen oh-my-zsh plugins/pip + zgen oh-my-zsh plugins/sudo + zgen oh-my-zsh plugins/aws + zgen oh-my-zsh plugins/chruby + zgen oh-my-zsh plugins/colored-man-pages + zgen oh-my-zsh plugins/git + zgen oh-my-zsh plugins/github + zgen oh-my-zsh plugins/python + zgen oh-my-zsh plugins/rsync + zgen oh-my-zsh plugins/screen + zgen oh-my-zsh plugins/vagrant + # check for autojump install before applying plugin + if type autojump >/dev/null 2>&1; then + zgen oh-my-zsh plugins/autojump + fi + zgen oh-my-zsh plugins/tmux + zgen oh-my-zsh plugins/tmuxinator - # when in a directory with vagrant/docker files can use start, stop, up, down - zgen load Cloudstek/zsh-plugin-appup + # when in a directory with vagrant/docker files can use start, stop, up, down + zgen load Cloudstek/zsh-plugin-appup - # Load more completion files for zsh from the zsh-lovers github repo. - zgen load zsh-users/zsh-completions src + # Load more completion files for zsh from the zsh-lovers github repo. + zgen load zsh-users/zsh-completions src - # Docker completion - zgen load srijanshetty/docker-zsh + # Docker completion + zgen load srijanshetty/docker-zsh - # Very cool plugin that generates zsh completion functions for commands - # if they have getopt-style help text. It doesn't generate them on the fly, - # you'll have to explicitly generate a completion, but it's still quite cool. - zgen load RobSis/zsh-completion-generator + # Very cool plugin that generates zsh completion functions for commands + # if they have getopt-style help text. It doesn't generate them on the fly, + # you'll have to explicitly generate a completion, but it's still quite cool. + zgen load RobSis/zsh-completion-generator - # Tab complete rakefile targets. - zgen load unixorn/rake-completion.zshplugin + # Tab complete rakefile targets. + zgen load unixorn/rake-completion.zshplugin - # Load me last - GENCOMPL_FPATH=$HOME/.zsh/complete + # Load me last + GENCOMPL_FPATH=$HOME/.zsh/complete - zgen save + zgen save } check_zgen_installation if ! zgen saved; then - load_plugins + load_plugins fi diff --git a/.config/shell/zshrc.d/1-set-up-powerlevel9k-theming.zsh b/.config/shell/zshrc.d/1-set-up-powerlevel9k-theming.zsh index 9716353..5e2384f 100644 --- a/.config/shell/zshrc.d/1-set-up-powerlevel9k-theming.zsh +++ b/.config/shell/zshrc.d/1-set-up-powerlevel9k-theming.zsh @@ -13,7 +13,7 @@ POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%F{blue}\u256D\u2500%F{white}" POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%F{blue}\u2570\uf460%F{white} " POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(root_indicator dir dir_writable_joined) POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time - vcs background_jobs_joined time_joined) + vcs background_jobs_joined time_joined) POWERLEVEL9K_VCS_MODIFIED_BACKGROUND="clear" POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND="clear" POWERLEVEL9K_VCS_MODIFIED_FOREGROUND="yellow" diff --git a/.config/shell/zshrc.d/6-mkcd.zsh b/.config/shell/zshrc.d/6-mkcd.zsh index f2e8a49..ff2c3a6 100644 --- a/.config/shell/zshrc.d/6-mkcd.zsh +++ b/.config/shell/zshrc.d/6-mkcd.zsh @@ -1,5 +1,5 @@ #!/bin/zsh # mkdir & cd -function mkcd { - mkdir -p "$@" && cd "$_" || return +function mkcd() { + mkdir -p "$@" && cd "$_" || return } diff --git a/.config/shell/zshrc.d/6-newest-files.zsh b/.config/shell/zshrc.d/6-newest-files.zsh index 6c6c3a1..fc726a4 100644 --- a/.config/shell/zshrc.d/6-newest-files.zsh +++ b/.config/shell/zshrc.d/6-newest-files.zsh @@ -1,10 +1,10 @@ #!/bin/zsh # show newest files # http://www.commandlinefu.com/commands/view/9015/find-the-most-recently-changed-files-recursively -newest (){ - find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | \ - grep -v cache | \ - grep -v '.hg' | grep -v '.git' | \ - sort -r | \ - less +newest() { + find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | + grep -v cache | + grep -v '.hg' | grep -v '.git' | + sort -r | + less } diff --git a/.config/shell/zshrc.d/6-ssht-tmux-attaching.zsh b/.config/shell/zshrc.d/6-ssht-tmux-attaching.zsh index 7ceb6ff..31668fe 100644 --- a/.config/shell/zshrc.d/6-ssht-tmux-attaching.zsh +++ b/.config/shell/zshrc.d/6-ssht-tmux-attaching.zsh @@ -1,6 +1,6 @@ #!/bin/zsh # automatically use tmux whenever we ssh to a server -function ssht(){ +function ssht() { ssh "$@" -t 'tmux a || tmux || /bin/bash' } diff --git a/.config/shell/zshrc.d/9-configure-autocompletion.zsh b/.config/shell/zshrc.d/9-configure-autocompletion.zsh index 7fb3ebf..b19402e 100644 --- a/.config/shell/zshrc.d/9-configure-autocompletion.zsh +++ b/.config/shell/zshrc.d/9-configure-autocompletion.zsh @@ -1,14 +1,15 @@ +#!/bin/zsh +# # Speed up autocomplete, force prefix mapping zstyle ':completion:*' accept-exact '*(N)' zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.zsh/cache # shellcheck disable=SC2016 -zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")'; +zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")' # Load any custom zsh completions we've installed if [ -d ~/.zsh-completions ]; then - for completion in ~/.zsh-completions/* - do + for completion in ~/.zsh-completions/*; do # shellcheck source=/dev/null source "$completion" done diff --git a/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh b/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh index 3f2cfe4..3f8aada 100644 --- a/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh +++ b/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh @@ -5,20 +5,18 @@ # In case a plugin adds a redundant path entry, remove duplicate entries # from PATH -# -# This snippet is from Mislav Marohnić 's -# dotfiles repo at https://github.com/mislav/dotfiles -dedupe_path() { - typeset -a paths result - paths=($path) - - while [[ ${#paths} -gt 0 ]]; do - p="${paths[1]}" - shift paths - [[ -z ${paths[(r)$p]} ]] && result+="$p" - done - - export PATH=${(j+:+)result} +# from: https://unix.stackexchange.com/questions/40749/remove-duplicate-path-entries-with-awk-command +get_var() { + eval 'printf "%s\n" "${'"$1"'}"' } - -dedupe_path +set_var() { + eval "$1=\"\$2\"" +} +dedup_pathvar() { + pathvar_name="$1" + pathvar_value="$(get_var "$pathvar_name")" + deduped_path="$(perl -e 'print join(":",grep { not $seen{$_}++ } split(/:/, $ARGV[0]))' "$pathvar_value")" + set_var "$pathvar_name" "$deduped_path" +} +dedup_pathvar PATH +dedup_pathvar MANPATH From 8d19ff9ffdb560dc8c188eec73bdf7b81d43ffc6 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 11:33:57 +0200 Subject: [PATCH 7/8] [gitlab] Make CI output colorful --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ddeb2a6..4a9155c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,9 +11,9 @@ analyze: - shellcheck --version script: - echo "--------- CHECKING POSIX SHELLSCRIPTS -------------" - - find . -type f -name '*.sh' | xargs shellcheck + - find . -type f -name '*.sh' | xargs shellcheck -Calways - echo "--------- CHECKING ZSH SHELLSCRIPTS -------------" - - find . -type f -name '*.zsh' | xargs shellcheck -s bash -e SC2034 + - find . -type f -name '*.zsh' | xargs shellcheck -Calways -s bash -e SC2034 lint: stage: test From dd6221632701a90196d2dd2be635aa3453cce98f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 11:37:59 +0200 Subject: [PATCH 8/8] [gitlab] Remove unit testing CI for now --- .gitlab-ci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4a9155c..f9b1f23 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,11 +24,3 @@ lint: - find . -type f -name '*.sh' | xargs shfmt -d -i 2 - echo "--------- CHECKING ZSH SHELLSCRIPTS -------------" - find . -type f -name '*.zsh' | xargs shfmt -d -i 2 - -test: - stage: test - image: bats/bats:latest - before_script: - - bats --version - script: - - bats -r .