From bedf7e18a904c00b3049c9ffe02a84c5dbc299ec Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 24 Jul 2019 10:54:06 +0200 Subject: [PATCH] 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