Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Commands #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
47 changes: 43 additions & 4 deletions aliasme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ _list() {
while read name
do
read value
echo "$name : $value"
read cmdType
echo "$name ($cmdType) : $value"
done < ~/.aliasme/cmd
fi
}
Expand All @@ -24,8 +25,19 @@ _add() {
read -ep "Input cmd to add:" cmd
fi

if [ "$3" == "d" ];then
cmdType="Dynamic"
elif [ "$3" == "f" ]; then
cmdType="Fill"
elif [ "$3" == "m" ]; then
cmdType="Multi Fill $4"
else
cmdType="Default"
fi

echo $name >> ~/.aliasme/cmd
echo $cmd >> ~/.aliasme/cmd
echo $cmdType >> ~/.aliasme/cmd
echo "add: $name -> $cmd"

_autocomplete
Expand All @@ -45,6 +57,7 @@ _remove() {
do
if [ "$line" = "$name" ]; then
read line #skip one more line
read cmdType
echo "remove $name"
else
echo $line >> ~/.aliasme/cmdtemp
Expand All @@ -60,7 +73,32 @@ _excute() {
while read -u9 line; do
if [ "$1" = "$line" ]; then
read -u9 line
eval $line
read -u9 cmdType
if [ "$cmdType" == "Default" ]; then
eval $line
elif [ "$cmdType" == "Dynamic" ]; then
cmds=()
for i in $(seq 2 $#); do
eval arg=\$$i
cmds+=$arg\
done
eval $line $cmds
elif [ "$cmdType" == "Fill" ]; then
cmds=()
for i in $(seq 2 $#); do
eval arg=\$$i
cmds+=$arg\
done
eval ${line//\?/$cmds}
else
fills=($cmdType)
for i in $(seq 1 ${fills[2]}); do
let num=$i+1
eval arg=\$$num
line=${line//\?$i/$arg}
done
eval $line
fi
return 0
fi
done 9< ~/.aliasme/cmd
Expand All @@ -80,6 +118,7 @@ _bashauto()
do
opts+=" $line"
read line
read line
done < ~/.aliasme/cmd
fi
COMPREPLY=( $(compgen -W "${opts}" ${cur}) )
Expand Down Expand Up @@ -112,7 +151,7 @@ al(){
if [ $1 = "ls" ]; then
_list
elif [ $1 = "add" ]; then
_add $2 "$3"
_add $2 "$3" $4 $5
elif [ $1 = "rm" ]; then
_remove $2
elif [ $1 = "-h" ]; then
Expand All @@ -127,7 +166,7 @@ al(){
echo "aliasme 3.0.0"
echo "visit https://github.com/Jintin/aliasme for more information"
else
if ! _excute $1 ; then
if ! _excute $@; then
echo "not found"
fi
fi
Expand Down