aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bash_include105
1 files changed, 105 insertions, 0 deletions
diff --git a/bash_include b/bash_include
index 8dadcaa..7e9aaad 100644
--- a/bash_include
+++ b/bash_include
@@ -413,6 +413,10 @@ function help_function ()
trash_rm [all | numbers ...] [-- prefix ...]
trash_count
trash_du [-- prefix ...]
+ <<< Group PATH Editor >>>
+ path_editor
+ split_path
+ update_path
<<< Other >>>
split_arguments [arguments ...]
compile_all [-n] filename ...
@@ -529,6 +533,107 @@ function check_important_files ()
done
}
+########## PATH Editor ##########
+
+function split_path ()
+{
+ local fifoname="$HOME/`uuidgen`"
+ mkfifo "$fifoname"
+ local -i i=0
+ local oneline
+ export patharr
+ echo "$current_path" | sed -e 's/:/ /g' | xargs -n 1 echo > "$fifoname" &
+ exec 3<"$fifoname"
+ while read -u 3 patharr[$i]
+ do
+ i=$i+1
+ done
+ exec 3<&-
+ unlink "$fifoname"
+ echo $oneline
+}
+
+function update_path ()
+{
+ current_path=''
+ local -i i=0
+ local firsttime="yes"
+ while [ "${patharr[$i]}" ]
+ do
+ if [ '!' "${patharr[$i]}" = ":" ]
+ then
+ if [ "$firsttime" ]
+ then
+ firsttime=''
+ else
+ current_path+=':'
+ fi
+ current_path+="${patharr[$i]}"
+ fi
+ i=$i+1
+ done
+}
+
+function path_editor ()
+{
+ export current_path="$PATH"
+ local should_continue="yes"
+ local command
+ local command_sub
+ local command_sub2
+ local -i i
+ while [ "$should_continue" ]
+ do
+ split_path
+ i=0
+ while [ "${patharr[$i]}" ]
+ do
+ echo "$i: ${patharr[$i]}"
+ i=$i+1
+ done
+ read -e -p "(A)ppend/(D)elete/(E)dit/(M)ove/(R)eset/(Q)uit ? " command
+ case "$command" in
+ A|a)
+ read -e -p "Type new entry: " patharr[$i]
+ update_path
+ ;;
+ D|d)
+ read -e -p "Line: " command_sub
+ patharr[$command_sub]=':'
+ update_path
+ ;;
+ E|e)
+ read -e -p "Line: " command_sub
+ read -e -p "Modify this entry: " -i "${patharr[$command_sub]}" patharr[$command_sub]
+ update_path
+ ;;
+ M|m)
+ read -e -p "Exchange: " command_sub
+ read -e -p "With: " command_sub2
+ swaptmp="${patharr[$command_sub]}"
+ patharr[$command_sub]="${patharr[$command_sub2]}"
+ patharr[$command_sub2]="$swaptmp"
+ unset swaptmp
+ update_path
+ ;;
+ R|r)
+ current_path="$PATH"
+ ;;
+ Q|q)
+ PATH="$current_path"
+ echo "PATH=$PATH"
+ should_continue=''
+ ;;
+ *)
+ echo " *** Unknown command *** "
+ ;;
+ esac
+ done
+ unset patharr
+}
+
+########## PATH Editor End ##########
+
# Doing something
check_important_files