From 7d3266a7086242ba05bcd00b56434eeef1c94beb Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sat, 2 Jan 2021 14:06:46 -0800 Subject: [PATCH 01/13] This chagne will allow aliasme.sh to run dynamic commands instead of just static commands. For example when you create something like this "al add new 'cd'". Then when you run "al new root/directory" then it will change your directory to "../root/directory" or anything base on your input. --- aliasme.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index ec465c6..296adc3 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -60,7 +60,11 @@ _excute() { while read -u9 line; do if [ "$1" = "$line" ]; then read -u9 line - eval $line + if [ ! -z $2 ]; then + eval $line $2 + else + eval $line + fi return 0 fi done 9< ~/.aliasme/cmd @@ -127,7 +131,7 @@ al(){ echo "aliasme 3.0.0" echo "visit https://github.com/Jintin/aliasme for more information" else - if ! _excute $1 ; then + if ! _excute $1 $2; then echo "not found" fi fi From 937fa766b1904055602eb85340d5f78b23076f86 Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sun, 3 Jan 2021 08:46:03 -0800 Subject: [PATCH 02/13] This change will allow for multiple parts dynamic commands --- aliasme.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index 296adc3..ab1b014 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -60,7 +60,16 @@ _excute() { while read -u9 line; do if [ "$1" = "$line" ]; then read -u9 line - if [ ! -z $2 ]; then + if [ "$2" == "MD" ]; then + cmds=() + for input in $@; do + if [[ $1 != $input ]] && [[ $2 != $input ]]; then + cmds+=$input + cmds+=" " + fi + done + eval $line $cmds + elif [ ! -z $2 ]; then eval $line $2 else eval $line @@ -131,7 +140,7 @@ al(){ echo "aliasme 3.0.0" echo "visit https://github.com/Jintin/aliasme for more information" else - if ! _excute $1 $2; then + if ! _excute $@; then echo "not found" fi fi From 247987e0be015d398437a3ce3d87ece5e3b3016a Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sun, 3 Jan 2021 10:00:27 -0800 Subject: [PATCH 03/13] Clean up code --- aliasme.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index ab1b014..2517104 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -62,11 +62,9 @@ _excute() { read -u9 line if [ "$2" == "MD" ]; then cmds=() - for input in $@; do - if [[ $1 != $input ]] && [[ $2 != $input ]]; then - cmds+=$input - cmds+=" " - fi + for i in $(seq 3 $#); do + eval arg=\$$i + cmds+=$arg\ done eval $line $cmds elif [ ! -z $2 ]; then From c2ba0c07b6bb78a78b2bc1a8b4e2b460b887678f Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sun, 3 Jan 2021 13:04:28 -0800 Subject: [PATCH 04/13] Instead adding onto a alias this change will allow you to also create alias where you can change its' contents per call --- aliasme.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aliasme.sh b/aliasme.sh index 2517104..b8e809c 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -67,6 +67,8 @@ _excute() { cmds+=$arg\ done eval $line $cmds + elif [ "$2" == "Fill" ]; then + eval "${line/\?/$3}" elif [ ! -z $2 ]; then eval $line $2 else From 077761f6b908403787f1327c4c109eae6d0c0cf4 Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sun, 3 Jan 2021 14:42:07 -0800 Subject: [PATCH 05/13] Added multi fill option --- aliasme.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aliasme.sh b/aliasme.sh index b8e809c..813e06d 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -67,8 +67,10 @@ _excute() { cmds+=$arg\ done eval $line $cmds - elif [ "$2" == "Fill" ]; then + elif [ "$2" == "F" ]; then eval "${line/\?/$3}" + elif [ "$2" == "MF" ]; then + eval "${line//\?/$3}" elif [ ! -z $2 ]; then eval $line $2 else From f2903efb140db8fa1b4a765e0804af4ea59643c9 Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sun, 3 Jan 2021 14:57:57 -0800 Subject: [PATCH 06/13] Removed the need to distinguish between a dynamic and multi dynamic alias --- aliasme.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index 813e06d..fe5e4d2 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -60,19 +60,17 @@ _excute() { while read -u9 line; do if [ "$1" = "$line" ]; then read -u9 line - if [ "$2" == "MD" ]; then + if [ "$2" == "F" ]; then + eval "${line/\?/$3}" + elif [ "$2" == "MF" ]; then + eval "${line//\?/$3}" + elif [ ! -z $2 ]; then cmds=() - for i in $(seq 3 $#); do + for i in $(seq 2 $#); do eval arg=\$$i cmds+=$arg\ done eval $line $cmds - elif [ "$2" == "F" ]; then - eval "${line/\?/$3}" - elif [ "$2" == "MF" ]; then - eval "${line//\?/$3}" - elif [ ! -z $2 ]; then - eval $line $2 else eval $line fi From 8b945abcadeb52476f24dd1833d56c81a02fa23b Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sun, 3 Jan 2021 17:14:35 -0800 Subject: [PATCH 07/13] Every alias now has cmdType Default, Dynamic, Fill, or Multi Fill. Some functions were modify to accommodate for cmdType. However autocomplete is broken. --- aliasme.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index fe5e4d2..b670f59 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -6,7 +6,8 @@ _list() { while read name do read value - echo "$name : $value" + read cmdType + echo "$name ($cmdType) : $value" done < ~/.aliasme/cmd fi } @@ -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" == "MF" ]; then + cmdType="Multi Fill" + else + cmdType="Default" + fi + echo $name >> ~/.aliasme/cmd echo $cmd >> ~/.aliasme/cmd + echo $cmdType >> ~/.aliasme/cmd echo "add: $name -> $cmd" _autocomplete @@ -45,9 +57,12 @@ _remove() { do if [ "$line" = "$name" ]; then read line #skip one more line + read cmdType echo "remove $name" + echo "remove $cmdType" else echo $line >> ~/.aliasme/cmdtemp + echo $cmdType >> ~/.aliasme/cmdtemp fi done < ~/.aliasme/cmd mv ~/.aliasme/cmdtemp ~/.aliasme/cmd @@ -60,11 +75,12 @@ _excute() { while read -u9 line; do if [ "$1" = "$line" ]; then read -u9 line - if [ "$2" == "F" ]; then - eval "${line/\?/$3}" - elif [ "$2" == "MF" ]; then - eval "${line//\?/$3}" - elif [ ! -z $2 ]; then + read -u9 cmdType + if [ "$cmdType" == "Fill" ]; then + eval "${line/\?/$2}" + elif [ "$cmdType" == "Multi Fill" ]; then + eval "${line//\?/$2}" + elif [ "$cmdType" == "Dynamic" ]; then cmds=() for i in $(seq 2 $#); do eval arg=\$$i From cd2c271e618f83fba9c5d561db12c8860bf1b1bb Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sun, 3 Jan 2021 18:52:12 -0800 Subject: [PATCH 08/13] Remove() is fixed --- aliasme.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index b670f59..1d770f5 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -59,10 +59,8 @@ _remove() { read line #skip one more line read cmdType echo "remove $name" - echo "remove $cmdType" else echo $line >> ~/.aliasme/cmdtemp - echo $cmdType >> ~/.aliasme/cmdtemp fi done < ~/.aliasme/cmd mv ~/.aliasme/cmdtemp ~/.aliasme/cmd From fb32b079004b79649ffdc8d9572e55e32ad7f629 Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Sun, 3 Jan 2021 19:27:28 -0800 Subject: [PATCH 09/13] Fixed autocomplete on the command line --- aliasme.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/aliasme.sh b/aliasme.sh index 1d770f5..99b8e54 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -107,6 +107,7 @@ _bashauto() do opts+=" $line" read line + read line done < ~/.aliasme/cmd fi COMPREPLY=( $(compgen -W "${opts}" ${cur}) ) From 7f46643d09d2bdaf9a36e967208cf60c4a43dd9e Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Mon, 4 Jan 2021 12:11:05 -0800 Subject: [PATCH 10/13] Fixed add() --- aliasme.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aliasme.sh b/aliasme.sh index 99b8e54..46f19b7 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -140,7 +140,7 @@ al(){ if [ $1 = "ls" ]; then _list elif [ $1 = "add" ]; then - _add $2 "$3" + _add $2 "$3" $4 elif [ $1 = "rm" ]; then _remove $2 elif [ $1 = "-h" ]; then From 1b4d3e7129bcdd51449771fc7d2ef02482967152 Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Mon, 4 Jan 2021 13:53:10 -0800 Subject: [PATCH 11/13] All Fills and Multi Fills are now just Fills. While the new Multi Fill is now is a combination of Fill and Dynamic --- aliasme.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index 46f19b7..9c85633 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -30,7 +30,7 @@ _add() { elif [ "$3" == "F" ]; then cmdType="Fill" elif [ "$3" == "MF" ]; then - cmdType="Multi Fill" + cmdType="Multi Fill $4" else cmdType="Default" fi @@ -74,9 +74,9 @@ _excute() { if [ "$1" = "$line" ]; then read -u9 line read -u9 cmdType - if [ "$cmdType" == "Fill" ]; then - eval "${line/\?/$2}" - elif [ "$cmdType" == "Multi Fill" ]; then + if [ "$cmdType" == "Default" ]; then + eval $line + elif [ "$cmdType" == "Fill" ]; then eval "${line//\?/$2}" elif [ "$cmdType" == "Dynamic" ]; then cmds=() @@ -86,6 +86,12 @@ _excute() { 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 @@ -140,7 +146,7 @@ al(){ if [ $1 = "ls" ]; then _list elif [ $1 = "add" ]; then - _add $2 "$3" $4 + _add $2 "$3" $4 $5 elif [ $1 = "rm" ]; then _remove $2 elif [ $1 = "-h" ]; then From 527aea5eba08bae14a1849cb28d031e8a6a9c5e3 Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Mon, 4 Jan 2021 16:50:11 -0800 Subject: [PATCH 12/13] Fills can now take multiple arguments and changed the declaration for each cmdType in add() --- aliasme.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index 9c85633..79709f4 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -25,11 +25,11 @@ _add() { read -ep "Input cmd to add:" cmd fi - if [ "$3" == "D" ];then + if [ "$3" == "d" ];then cmdType="Dynamic" - elif [ "$3" == "F" ]; then + elif [ "$3" == "f" ]; then cmdType="Fill" - elif [ "$3" == "MF" ]; then + elif [ "$3" == "m" ]; then cmdType="Multi Fill $4" else cmdType="Default" @@ -76,8 +76,6 @@ _excute() { read -u9 cmdType if [ "$cmdType" == "Default" ]; then eval $line - elif [ "$cmdType" == "Fill" ]; then - eval "${line//\?/$2}" elif [ "$cmdType" == "Dynamic" ]; then cmds=() for i in $(seq 2 $#); do @@ -85,6 +83,13 @@ _excute() { 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 From 5513dda90d463cac19063bdba9696fcc4174ec0a Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Mon, 4 Jan 2021 18:05:22 -0800 Subject: [PATCH 13/13] Code clean up --- aliasme.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aliasme.sh b/aliasme.sh index 79709f4..41018ae 100644 --- a/aliasme.sh +++ b/aliasme.sh @@ -89,9 +89,9 @@ _excute() { eval arg=\$$i cmds+=$arg\ done - eval "${line//\?/$cmds}" + eval ${line//\?/$cmds} else - fills=(${cmdType// / }) + fills=($cmdType) for i in $(seq 1 ${fills[2]}); do let num=$i+1 eval arg=\$$num