diff options
author | LAN-TW <lantw44@gmail.com> | 2011-12-15 00:00:15 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2011-12-15 00:00:15 +0800 |
commit | e2a8abca2c7ffd29e347ba4a5ea478d765a58e08 (patch) | |
tree | 07313410c79fd0c759af3a607706ff03b5475b8b | |
parent | 82e1dbabf647beb06b6c0ebf5b22aeb208a04bc3 (diff) | |
download | configfile-e2a8abca2c7ffd29e347ba4a5ea478d765a58e08.tar configfile-e2a8abca2c7ffd29e347ba4a5ea478d765a58e08.tar.gz configfile-e2a8abca2c7ffd29e347ba4a5ea478d765a58e08.tar.bz2 configfile-e2a8abca2c7ffd29e347ba4a5ea478d765a58e08.tar.lz configfile-e2a8abca2c7ffd29e347ba4a5ea478d765a58e08.tar.xz configfile-e2a8abca2c7ffd29e347ba4a5ea478d765a58e08.tar.zst configfile-e2a8abca2c7ffd29e347ba4a5ea478d765a58e08.zip |
bash_include: 加入 PATH 互動式編輯器bash_include-20111214
-rw-r--r-- | bash_include | 105 |
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 |