nsalias - namespaced aliases

This commit is contained in:
Adolfo Perez Alvarez 2023-06-28 13:53:29 +02:00
parent e57032ae8b
commit 5913fd722a

32
nsalias Normal file
View File

@ -0,0 +1,32 @@
function nsalias {
typeset -i i=0
case $# in
0|1)
while (( i < ${#NSCMDNS[@]} ))
do
[[ ( -z $1 ) || ( ${NSCMDNS[i]} = $1 ) ]] \
&& print -c "${NSCMDNS[i]}\t${NSCMDFN[i]}\t${NSCMDSH[i]}"
let i++
done
;;
2)
while [[ $i -lt ${#NSCMDNS[@]} && ( ${NSCMDNS[i]} != $1 || ${NSCMDFN[i]} != $2 ) ]]
do
let i++
done
(( i == ${#NSCMDNS[@]} )) && return 1
eval "${NSCMDSH[i]}"
;;
3)
(( $# != 3 )) && return 64
NSCMDNS[${#NSCMDNS[@]}]=$1
NSCMDFN[${#NSCMDFN[@]}]=$2
NSCMDSH[${#NSCMDSH[@]}]=$3
! alias $1 >/dev/null && alias $1="nsalias $1"
;;
*)
return 64
;;
esac
}