diff options
Diffstat (limited to '.config/init')
-rwxr-xr-x | .config/init/funcs/srcopen | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/.config/init/funcs/srcopen b/.config/init/funcs/srcopen index d910fee..c427488 100755 --- a/.config/init/funcs/srcopen +++ b/.config/init/funcs/srcopen @@ -1,8 +1,10 @@ #!/usr/bin/env zsh # edit all source files of type under a directory -local search_strs -typeset -A search_strs +local search_map +typeset -A search_map +local keys +typeset -a keys local k local koff local i @@ -12,20 +14,25 @@ local input local file_list typeset -a file_list -search_strs=( - "c" ".*\.(c|h)" - "crystal" ".*\.(cr|h)" - "css" ".*\.(css|scss)" - "elixir" ".*\.(ex|exs)" - "go" ".*\.go" - "html" ".*\.(html|xhtml)" - "markdown" ".*\.md" - "ocaml" ".*\.(ml|mli)" - "js" ".*\.js" - "tex" ".*\.tex" - "vim" ".*\.vim" +search_map=( + "c" "\.(c|h)" + "crystal" "\.cr" + "css" "\.(css|scss)" + "elixir" "\.(ex|exs)" + "go" "\.go" + "html" "\.(html|xhtml)" + "markdown" "\.md" + "ocaml" "\.(ml|mli)" + "js" "\.js" + "tex" "\.tex" + "vim" "\.vim" ) +{ + printf "%s\0" ${(k)search_map} | sort -z | head -c -1 + printf "\n" +} | IFS=$'\0' read -r -A keys + [[ $#@ -eq 0 ]] && return [[ $EDITOR == "" ]] && return @@ -50,11 +57,9 @@ function draw_main() { zcurses attr stdscr -bold - i=0 - for k in ${(@k)search_strs}; do - zcurses move stdscr $((i + 2)) 0 - zcurses string stdscr $k - i=$((i + 1)) + for i in {1..$#keys}; do + zcurses move stdscr $((1 + i)) 0 + zcurses string stdscr $keys[$i] done } @@ -65,7 +70,7 @@ draw_main input="" while true; do - zcurses move stdscr $(($#search_strs + 3)) 0 + zcurses move stdscr $(($#search_map + 3)) 0 zcurses clear stdscr bot zcurses string stdscr "-: $input" zcurses refresh stdscr @@ -85,7 +90,7 @@ while true; do if [[ $char == $'\t' ]]; then seen="false" - for k in ${(@k)search_strs}; do + for k in ${(@k)search_map}; do [[ $k =~ "^${input}.*$" ]] || continue [[ $seen == "true" ]] && seen="false" && break seen="true" @@ -108,8 +113,15 @@ done zcurses end -[[ $input == "" ]] && return +[[ $input == "" || $search_map[$input] == "" ]] && return -file_list=( $(find $@ -regextype posix-extended -regex $search_strs[$input]) ) +{ + find $@ \ + -regextype posix-extended \ + -regex "^(/[^.]|[^/])*$search_map[$input]\$" \ + -print0 \ + | head -c -1 + printf "\n" +}| IFS=$'\0' read -r -A file_list [[ $#file_list -ne 0 ]] && $EDITOR -- $file_list |