shell/*: fix most shellcheck errors

This commit is contained in:
Felix Buehler 2021-12-06 12:41:02 +01:00
parent ced309e5a4
commit 0d8a6f0c01
9 changed files with 67 additions and 53 deletions

View file

@ -34,13 +34,13 @@ alias of="xdg-open"
# io <processname> # io <processname>
io(){ io(){
local sudo_needed local sudo_needed
[ ! -z "$(type sudo 2>/dev/null)" -a "$USER" != 'root' ] \ [ -n "$(type sudo 2>/dev/null)" ] && [ "$USER" != 'root' ] \
&& sudo_needed="sudo" && sudo_needed="sudo"
${sudo_needed} iotop -p$(pidof "$1" | sed 's/ / -p/g') ${sudo_needed} iotop -p"$(pidof "$1" | sed 's/ / -p/g')"
} }
if [ ! -z "$(type sudo 2>/dev/null)" -a "$USER" != 'root' ]; then if [ -n "$(type sudo 2>/dev/null)" ] && [ "$USER" != 'root' ]; then
#create sudo aliases WITHOUT leading s #create sudo aliases WITHOUT leading s
for sudo in fwupdmgr mount umount iftop iotop fsadm lvchange lvconvert lvcreate lvdisplay lvextend lvm lvmchange lvmconf lvmconfig lvmdiskscan lvmdump lvmetad lvmsadc lvmsar lvreduce lvremove lvrename lvresize lvs lvscan pvchange pvck pvcreate pvdisplay pvmove pvremove pvresize pvs pvscan vgcfgbackup vgcfgrestore vgchange vgck vgconvert vgcreate vgdisplay vgexport vgextend vgimport vgimportclone vgmerge vgmknodes vgreduce vgremove vgrename vgs vgscan vgsplit; for sudo in fwupdmgr mount umount iftop iotop fsadm lvchange lvconvert lvcreate lvdisplay lvextend lvm lvmchange lvmconf lvmconfig lvmdiskscan lvmdump lvmetad lvmsadc lvmsar lvreduce lvremove lvrename lvresize lvs lvscan pvchange pvck pvcreate pvdisplay pvmove pvremove pvresize pvs pvscan vgcfgbackup vgcfgrestore vgchange vgck vgconvert vgcreate vgdisplay vgexport vgextend vgimport vgimportclone vgmerge vgmknodes vgreduce vgremove vgrename vgs vgscan vgsplit;
do do
@ -61,7 +61,7 @@ if [ ! -z "$(type sudo 2>/dev/null)" -a "$USER" != 'root' ]; then
# which should indicate in most times if we need sudo # which should indicate in most times if we need sudo
echo "$*" | grep -- "-[SRU]" >/dev/null 2>&1 \ echo "$*" | grep -- "-[SRU]" >/dev/null 2>&1 \
&& sudo_needed="sudo" && sudo_needed="sudo"
${sudo_needed} /usr/bin/pacman $* ${sudo_needed} /usr/bin/pacman "$@"
} }
fi fi
@ -116,8 +116,10 @@ dpms(){
xset s off xset s off
xset dpms "${secs}" "${secs}" "${secs}" xset dpms "${secs}" "${secs}" "${secs}"
} }
# IPv6 ping
for INTERFACE in $(ls /sys/class/net); do for INTERFACE in /sys/class/net/*; do
[ -e "$INTERFACE" ] || break # incase it is empty
INTERFACE=$(basename "$INTERFACE")
alias ping-all-$INTERFACE="ping -6 ff02::1%$INTERFACE" alias ping-all-$INTERFACE="ping -6 ff02::1%$INTERFACE"
alias ping-routes-$INTERFACE="ping -6 ff02::2%$INTERFACE" alias ping-routes-$INTERFACE="ping -6 ff02::2%$INTERFACE"
done done

View file

@ -2,12 +2,12 @@
#correct some fast tipped cds #correct some fast tipped cds
c() { c() {
if [ "$1" == "d.." ]; then if [ "$1" = "d.." ]; then
cd ..; cd ..;
pwd; pwd;
fi fi
if [ -d "$1" ]; then if [ -d "$1" ]; then
cd "$1"; cd "$1" || exit;
pwd; pwd;
fi fi
return 0; return 0;

View file

@ -2,10 +2,12 @@
# arch # arch
if [ "${BASH_VERSION}" ] && [ -r /usr/share/doc/pkgfile/command-not-found.bash ]; then if [ "${BASH_VERSION}" ] && [ -r /usr/share/doc/pkgfile/command-not-found.bash ]; then
# shellcheck source=/dev/null
. /usr/share/doc/pkgfile/command-not-found.bash . /usr/share/doc/pkgfile/command-not-found.bash
fi fi
if [ "${ZSH_VERSION}" ] && [ -r /usr/share/doc/pkgfile/command-not-found.zsh ]; then if [ "${ZSH_VERSION}" ] && [ -r /usr/share/doc/pkgfile/command-not-found.zsh ]; then
# shellcheck source=/dev/null
. /usr/share/doc/pkgfile/command-not-found.zsh . /usr/share/doc/pkgfile/command-not-found.zsh
fi fi

View file

@ -1,55 +1,55 @@
#!/bin/sh #!/bin/sh
x() { x() {
for zipfile in $*; do for zipfile in "$@"; do
local extractor _x_extractor
if [ -f "$zipfile" ]; then if [ -f "$zipfile" ]; then
case "$zipfile" in case "$zipfile" in
*.deb) *.deb)
extractor="ar x" ;; _x_extractor="ar x" ;;
*.tar.lrz) *.tar.lrz)
extractor="lrztar -d" ;; _x_extractor="lrztar -d" ;;
*.lrz) *.lrz)
extractor="lrunzip" ;; _x_extractor="lrunzip" ;;
*.tar.bz2) *.tar.bz2)
extractor="bsdtar xjf" ;; _x_extractor="bsdtar xjf" ;;
*.bz2) *.bz2)
extractor="bunzip2" ;; _x_extractor="bunzip2" ;;
*.tar.gz) *.tar.gz)
extractor="bsdtar xzf" ;; _x_extractor="bsdtar xzf" ;;
*.gz) *.gz)
extractor="gunzip" ;; _x_extractor="gunzip" ;;
*.tar.xz) *.tar.xz)
extractor="bsdtar Jxf" ;; _x_extractor="bsdtar Jxf" ;;
*.xz) *.xz)
extractor="xz -d" ;; _x_extractor="xz -d" ;;
*.rar) *.rar)
extractor="unrar e" ;; _x_extractor="unrar e" ;;
*.tar) *.tar)
extractor="bsdtar xf" ;; _x_extractor="bsdtar xf" ;;
*.tbz2) *.tbz2)
extractor="bsdtar xjf" ;; _x_extractor="bsdtar xjf" ;;
*.tgz) *.tgz)
extractor="bsdtar xzf" ;; _x_extractor="bsdtar xzf" ;;
*.zip) *.zip)
extractor="unzip" ;; _x_extractor="unzip" ;;
*.Z) *.Z)
extractor="uncompress" ;; _x_extractor="uncompress" ;;
*.7z) *.7z)
extractor="7z x" ;; _x_extractor="7z x" ;;
*) *)
echo "Cannot extract '$zipfile': No extractor for filetype known ..." >&2 echo "Cannot extract '$zipfile': No extractor for filetype known ..." >&2
return 1 return 1
;; ;;
esac esac
if ! command -v `echo $extractor | awk '{print $1}'` >/dev/null 2>/dev/null; then if ! command -v "$(echo "$_x_extractor" | awk '{print $1}')" >/dev/null 2>/dev/null; then
echo "Cannot extract '$zipfile': Cannot find extractor '`echo $extractor | awk '{print $1}'`'." >&2 echo "Cannot extract '$zipfile': Cannot find extractor '$(echo "$_x_extractor" | awk '{print $1}')'." >&2
return 1 return 1
fi fi
echo "Extracting '$zipfile'..." >&2 echo "Extracting '$zipfile'..." >&2
eval $extractor $zipfile eval "$_x_extractor" "$zipfile"
elif [ ! -e "$zipfile" ]; then elif [ ! -e "$zipfile" ]; then
echo "Cannot extract '$zipfile': File does not exist!" echo "Cannot extract '$zipfile': File does not exist!"

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Assert an ssh-agent (which is empty at the beginning) # Assert an ssh-agent (which is empty at the beginning)
if command -v keychain 2>&1 >/dev/null; then if command -v keychain > /dev/null 2>&1; then
eval $(keychain -q --nogui --agents ssh --timeout 600 --eval) eval "$(keychain -q --nogui --agents ssh --timeout 600 --eval)"
fi fi

View file

@ -1,16 +1,25 @@
#!/bin/sh #!/bin/sh
if [ -z "${IN_NIX_SHELL}" ]; then if [ -z "${IN_NIX_SHELL}" ]; then
# shellcheck disable=SC2034 # Unused variables left for readability
LP_ENABLE_TITLE=1 LP_ENABLE_TITLE=1
# shellcheck disable=SC2034 # Unused variables left for readability
LP_ENABLE_SSH_COLORS=1 LP_ENABLE_SSH_COLORS=1
# shellcheck disable=SC2034 # Unused variables left for readability
LP_ENABLE_VCS_ROOT=1 LP_ENABLE_VCS_ROOT=1
# shellcheck disable=SC2034 # Unused variables left for readability
LP_DISABLED_VCS_PATH="" LP_DISABLED_VCS_PATH=""
# shellcheck disable=SC2034 # Unused variables left for readability
LP_ENABLE_TEMP=0 LP_ENABLE_TEMP=0
# shellcheck disable=SC2034 # Unused variables left for readability
LP_ENABLE_BATT=0 LP_ENABLE_BATT=0
# shellcheck disable=SC2034 # Unused variables left for readability
LP_ENABLE_SUDO=1 LP_ENABLE_SUDO=1
# Show the time for commands executing longer than 5 seconds # Show the time for commands executing longer than 5 seconds
# shellcheck disable=SC2034 # Unused variables left for readability
LP_RUNTIME_THRESHOLD=5 LP_RUNTIME_THRESHOLD=5
source ~/.liquidprompt/liquidprompt # shellcheck source=../bash/liquidprompt/liquidprompt
. ~/.liquidprompt/liquidprompt
fi fi

View file

@ -2,6 +2,7 @@
for profile in ~/.profile.d/*.sh; do for profile in ~/.profile.d/*.sh; do
if [ -x "$profile" ]; then if [ -x "$profile" ]; then
source $profile # shellcheck source=/dev/null
. "$profile"
fi fi
done done

View file

@ -5,35 +5,35 @@
#arg1: user where to find a config-file #arg1: user where to find a config-file
# if not given, it uses the current user in the $HOME and $USER-Variable # if not given, it uses the current user in the $HOME and $USER-Variable
function mysqlpw() { mysqlpw() {
local H=$HOME _mysqlpw_H=$HOME
local U=$USER _mysqlpw_U=$USER
# use different user, if arg1 given # use different user, if arg1 given
if [ ! -z $1 ]; then if [ -n "$1" ]; then
# check if given user is even existing # check if given user is even existing
if ! id $1 >/dev/null 2>/dev/null; then if ! id "$1" >/dev/null 2>/dev/null; then
echo user $1 not existing >&2 echo user "$1" not existing >&2
return 1 return 1
fi fi
U=$1 _mysqlpw_U=$1
H=`grep ^$1: /etc/passwd | cut -d ":" -f 6` _mysqlpw_H=$(grep ^"$1": /etc/passwd | cut -d ":" -f 6)
fi; fi;
local mysql_cnf="$H/.my.cnf" _mysqlpw_cnf="$_mysqlpw_H/.my.cnf"
if [ ! -e $mysql_cnf ]; then if [ ! -e "$_mysqlpw_cnf" ]; then
echo $mysql_cnf not existing >&2 && return 1 echo "$_mysqlpw_cnf" not existing >&2 && return 1
fi fi
if [ ! -r $mysql_cnf ]; then if [ ! -r "$_mysqlpw_cnf" ]; then
echo $mysql_cnf not readable >&2 && return 1 echo "$_mysqlpw_cnf" not readable >&2 && return 1
fi fi
local PW=`(grep "password=" $mysql_cnf || echo undefined) | cut -d "=" -f 2` _mysqlpw_PW=$( (grep "password=" "$_mysqlpw_cnf" || echo undefined) | cut -d "=" -f 2)
echo MySQL-Password for user $U is $PW echo MySQL-Password for user "$_mysqlpw_U" is "$_mysqlpw_PW"
} }

View file

@ -6,7 +6,7 @@ appendpath () {
*:"$1":*) *:"$1":*)
;; ;;
*) *)
if [[ -d "$1" ]]; then if [ -d "$1" ]; then
export PATH="${PATH:+$PATH:}$1" export PATH="${PATH:+$PATH:}$1"
fi fi
esac esac
@ -16,11 +16,11 @@ appendpath ~/.local/bin/
appendpath ~/.bin appendpath ~/.bin
if which ruby >/dev/null 2>&1 && which gem >/dev/null 2>&1; then if which ruby >/dev/null 2>&1 && which gem >/dev/null 2>&1; then
appendpath $(ruby -r rubygems -e 'puts Gem.user_dir')/bin appendpath "$(ruby -r rubygems -e 'puts Gem.user_dir')"/bin
fi fi
# PERL cpan modules # PERL cpan modules
appendpath $HOME/.perl/5/bin appendpath "$HOME"/.perl/5/bin
export PERL5LIB="$HOME/.perl/5/lib/perl5:$PERL5LIB" export PERL5LIB="$HOME/.perl/5/lib/perl5:$PERL5LIB"
export PERL_LOCAL_LIB_ROOT="$HOME/.perl/5:$PERL_LOCAL_LIB_ROOT" export PERL_LOCAL_LIB_ROOT="$HOME/.perl/5:$PERL_LOCAL_LIB_ROOT"
export PERL_MB_OPT="--install_base \"$HOME/.perl/5\"" export PERL_MB_OPT="--install_base \"$HOME/.perl/5\""
@ -28,5 +28,5 @@ export PERL_MM_OPT="INSTALL_BASE=$HOME/.perl/5"
export GOPATH=$HOME/.go export GOPATH=$HOME/.go
export GOBIN=$HOME/.gobin export GOBIN=$HOME/.gobin
appendpath $GOPATH/bin appendpath "$GOPATH"/bin
appendpath $GOBIN appendpath "$GOBIN"