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(){
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} 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
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
@ -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
echo "$*" | grep -- "-[SRU]" >/dev/null 2>&1 \
&& sudo_needed="sudo"
${sudo_needed} /usr/bin/pacman $*
${sudo_needed} /usr/bin/pacman "$@"
}
fi
@ -116,8 +116,10 @@ dpms(){
xset s off
xset dpms "${secs}" "${secs}" "${secs}"
}
for INTERFACE in $(ls /sys/class/net); do
# IPv6 ping
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-routes-$INTERFACE="ping -6 ff02::2%$INTERFACE"
done

View file

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

View file

@ -2,10 +2,12 @@
# arch
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
fi
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
fi

View file

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

View file

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

View file

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

View file

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

View file

@ -5,35 +5,35 @@
#arg1: user where to find a config-file
# if not given, it uses the current user in the $HOME and $USER-Variable
function mysqlpw() {
local H=$HOME
local U=$USER
mysqlpw() {
_mysqlpw_H=$HOME
_mysqlpw_U=$USER
# use different user, if arg1 given
if [ ! -z $1 ]; then
if [ -n "$1" ]; then
# check if given user is even existing
if ! id $1 >/dev/null 2>/dev/null; then
echo user $1 not existing >&2
if ! id "$1" >/dev/null 2>/dev/null; then
echo user "$1" not existing >&2
return 1
fi
U=$1
H=`grep ^$1: /etc/passwd | cut -d ":" -f 6`
_mysqlpw_U=$1
_mysqlpw_H=$(grep ^"$1": /etc/passwd | cut -d ":" -f 6)
fi;
local mysql_cnf="$H/.my.cnf"
_mysqlpw_cnf="$_mysqlpw_H/.my.cnf"
if [ ! -e $mysql_cnf ]; then
echo $mysql_cnf not existing >&2 && return 1
if [ ! -e "$_mysqlpw_cnf" ]; then
echo "$_mysqlpw_cnf" not existing >&2 && return 1
fi
if [ ! -r $mysql_cnf ]; then
echo $mysql_cnf not readable >&2 && return 1
if [ ! -r "$_mysqlpw_cnf" ]; then
echo "$_mysqlpw_cnf" not readable >&2 && return 1
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":*)
;;
*)
if [[ -d "$1" ]]; then
if [ -d "$1" ]; then
export PATH="${PATH:+$PATH:}$1"
fi
esac
@ -16,11 +16,11 @@ appendpath ~/.local/bin/
appendpath ~/.bin
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
# PERL cpan modules
appendpath $HOME/.perl/5/bin
appendpath "$HOME"/.perl/5/bin
export PERL5LIB="$HOME/.perl/5/lib/perl5:$PERL5LIB"
export PERL_LOCAL_LIB_ROOT="$HOME/.perl/5:$PERL_LOCAL_LIB_ROOT"
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 GOBIN=$HOME/.gobin
appendpath $GOPATH/bin
appendpath $GOBIN
appendpath "$GOPATH"/bin
appendpath "$GOBIN"