Skip to content
Permalink
Browse files

Run autoloaded functions through shellcheck

This also fixes some problems with the autoloaded functions that I
noticed while addressing the shellcheck warnings.
  • Loading branch information...
krader1961 committed Oct 30, 2019
1 parent 651e614 commit 286203fca7ccce7d1555e75e1a27646ba63f1a47
@@ -1,4 +1,7 @@
#!/bin/sh -x
# Run shellcheck on scripts under bin and scripts directories
# shellcheck disable=SC2046,SC2038
shellcheck $(find .copr/ scripts/ bin/ src/lib/libast/tests | xargs file | grep "shell script" | cut -d':' -f1)
shellcheck -s ksh $(find .copr bin scripts src/cmd/ksh93/functions src/lib/libast/tests -type f |
xargs file |
grep "shell script" |
cut -d':' -f1)
@@ -33,6 +33,7 @@ function _cd {

if (( type < 3 ))
then
# shellcheck disable=SC2154
if (( n >= _push_max + 1 ))
then
print -u2 cd: Directory stack not that deep.
@@ -63,7 +64,8 @@ function _cd {
dir="~"
;;
/*) ;;
*) dir="~/$dir"
*) # shellcheck disable=SC2088
dir="~/$dir"
;;
esac

@@ -1,3 +1,4 @@
#!/usr/bin/env ksh
#
# Given a ksh man page emit the text of the SYNOPSIS and FLAGS sections and nothing else. This is
# primarily meant to be used by builtins (either special or normal commands) to emit a subset of its
@@ -12,8 +12,8 @@ function dirs {
;;
esac

PS3=''
select i in "$dir" "${_push_stack[@]}"
# shellcheck disable=SC2154
select _ in "$dir" "${_push_stack[@]}"
do
:
done < /dev/null
@@ -10,11 +10,9 @@ function mcd {
esac

PS3='Select by number or enter a name: '
# shellcheck disable=SC2154
select dir in "$dir" "${_push_stack[@]}"
do
if _cd $REPLY
then
return
fi
_cd "$REPLY" && return
done
}
@@ -1,111 +1,36 @@
#
# DIRECTORY MANIPULATION FUNCTIONS PUSHD, POPD AND DIRS
#
# Uses global parameters _push_max _push_top _push_stack
integer _push_max=100 _push_top=100
# Display directory stack -- $HOME displayed as ~
function dirs
{
typeset dir="${PWD#$HOME/}"
case $dir in
$HOME)
dir=\~
;;
/*) ;;
*) dir=\~/$dir
esac
print -r - "$dir ${_push_stack[@]}"
}

# Change directory and put directory on front of stack
function pushd
{
typeset dir= type=0
integer i
case $1 in
"") # pushd
if ((_push_top >= _push_max))
then print pushd: No other directory.
return 1
fi
type=1 dir=${_push_stack[_push_top]}
;;
+[1-9]|+[1-9][0-9]) # pushd +n
integer i=_push_top$1-1
if ((i >= _push_max))
then print pushd: Directory stack not that deep.
return 1
fi
type=2 dir=${_push_stack[i]}
;;
*) if ((_push_top <= 0))
then print pushd: Directory stack overflow.
return 1
fi
esac
case $dir in
\~*) dir=$HOME${dir#\~}
esac
cd "${dir:-$1}" > /dev/null || return 1
dir=${OLDPWD#$HOME/}
case $dir in
$HOME)
dir=\~
;;
/*) ;;
*) dir=\~/$dir
esac
case $type in
0) # pushd name
_push_stack[_push_top=_push_top-1]=$dir
;;
1) # pushd
_push_stack[_push_top]=$dir
;;
2) # push +n
type=${1#+} i=_push_top-1
set -- "${_push_stack[@]}" "$dir" "${_push_stack[@]}"
shift $type
for dir
do (((i=i+1) < _push_max)) || break
_push_stack[i]=$dir
done
esac
dirs
}

# Pops the top directory
function popd
{
function popd {
typeset dir
if ((_push_top >= _push_max))
# shellcheck disable=SC2154
if ((_push_top >= _push_max))
then print popd: Nothing to pop.
return 1
return 1
fi
case $1 in
case $1 in
"")
dir=${_push_stack[_push_top]}
case $dir in
\~*) dir=$HOME${dir#\~}
\~*) dir=$HOME${dir#\~}
esac
cd "$dir" || return 1
;;
+[1-9]|+[1-9][0-9])
typeset savedir
integer i=_push_top$1-1
if ((i >= _push_max))
then print pushd: Directory stack not that deep.
return 1
integer i=$((_push_top - $1))
if ((i >= _push_max))
then
print pushd: Directory stack not that deep.
return 1
fi
while ((i > _push_top))
do _push_stack[i]=${_push_stack[i-1]}
i=i-1
do
_push_stack[i]=${_push_stack[i-1]}
i=$((i - 1))
done
;;
*) print pushd: Bad directory.
return 1
esac
unset '_push_stack[_push_top]'
_push_top=_push_top+1
_push_top=$((_push_top + 1))
dirs
}
@@ -1,46 +1,33 @@
#
# DIRECTORY MANIPULATION FUNCTIONS PUSHD, POPD AND DIRS
#
# Uses global parameters _push_max _push_top _push_stack
integer _push_max=100 _push_top=100
# Display directory stack -- $HOME displayed as ~
function dirs
{
typeset dir="${PWD#$HOME/}"
case $dir in
$HOME)
dir=\~
;;
/*) ;;
*) dir=\~/$dir
esac
print -r - "$dir ${_push_stack[@]}"
}

# Change directory and put directory on front of stack
function pushd
{
typeset dir= type=0
function pushd {
typeset dir=''
typeset type=0
integer i
case $1 in
"") # pushd
if ((_push_top >= _push_max))
then print pushd: No other directory.
return 1
# shellcheck disable=SC2154
if ((_push_top >= _push_max))
then
print pushd: No other directory.
return 1
fi
type=1 dir=${_push_stack[_push_top]}
type=1
dir=${_push_stack[_push_top]}
;;
+[1-9]|+[1-9][0-9]) # pushd +n
integer i=_push_top$1-1
if ((i >= _push_max))
then print pushd: Directory stack not that deep.
return 1
integer i=$((_push_top - $1))
if ((i >= _push_max))
then
print pushd: Directory stack not that deep.
return 1
fi
type=2 dir=${_push_stack[i]}
type=2
dir=${_push_stack[i]}
;;
*) if ((_push_top <= 0))
then print pushd: Directory stack overflow.
return 1
*) if ((_push_top <= 0))
then
print pushd: Directory stack overflow.
return 1
fi
esac
case $dir in
@@ -57,55 +44,22 @@ function pushd
esac
case $type in
0) # pushd name
_push_stack[_push_top=_push_top-1]=$dir
_push_top=$((_push_top - 1))
_push_stack[_push_top]=$dir
;;
1) # pushd
_push_stack[_push_top]=$dir
;;
2) # push +n
type=${1#+} i=_push_top-1
type=${1#+}
set -- "${_push_stack[@]}" "$dir" "${_push_stack[@]}"
shift $type
shift "$type"
integer i=$(( _push_top - 1 ))
for dir
do (((i=i+1) < _push_max)) || break
do
(( (i = i + 1) < _push_max )) || break
_push_stack[i]=$dir
done
esac
dirs
}

# Pops the top directory
function popd
{
typeset dir
if ((_push_top >= _push_max))
then print popd: Nothing to pop.
return 1
fi
case $1 in
"")
dir=${_push_stack[_push_top]}
case $dir in
\~*) dir=$HOME${dir#\~}
esac
cd "$dir" || return 1
;;
+[1-9]|+[1-9][0-9])
typeset savedir
integer i=_push_top$1-1
if ((i >= _push_max))
then print pushd: Directory stack not that deep.
return 1
fi
while ((i > _push_top))
do _push_stack[i]=${_push_stack[i-1]}
i=i-1
done
;;
*) print pushd: Bad directory.
return 1
esac
unset '_push_stack[_push_top]'
_push_top=_push_top+1
dirs
}

0 comments on commit 286203f

Please sign in to comment.
You can’t perform that action at this time.