diff options
author | katherine <ageha@airen-no-jikken.icu> | 2021-08-04 00:06:44 -0700 |
---|---|---|
committer | katherine <ageha@airen-no-jikken.icu> | 2021-08-04 00:06:44 -0700 |
commit | 819a54de34713096c9a25d6fc61bc4c28bfe91f0 (patch) | |
tree | 341afe6a4b290ef7b2bd9edbfd141015ac680e1c | |
parent | 312b67eb994c8decfa0606b6a54e9ec9226cafa3 (diff) | |
download | dotfiles-819a54de34713096c9a25d6fc61bc4c28bfe91f0.tar.gz |
add srcopen
-rw-r--r-- | .config/init/funcreqs/srcopen | 2 | ||||
-rwxr-xr-x | .config/init/funcs/srcopen | 115 | ||||
-rw-r--r-- | .config/ranger/rifle.conf | 14 |
3 files changed, 126 insertions, 5 deletions
diff --git a/.config/init/funcreqs/srcopen b/.config/init/funcreqs/srcopen new file mode 100644 index 0000000..4891a58 --- /dev/null +++ b/.config/init/funcreqs/srcopen @@ -0,0 +1,2 @@ +func_init_prereqs=($EDITOR) +func_init_checks=() diff --git a/.config/init/funcs/srcopen b/.config/init/funcs/srcopen new file mode 100755 index 0000000..d910fee --- /dev/null +++ b/.config/init/funcs/srcopen @@ -0,0 +1,115 @@ +#!/usr/bin/env zsh +# edit all source files of type under a directory + +local search_strs +typeset -A search_strs +local k +local koff +local i +typeset -i i +local char +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" +) + +[[ $#@ -eq 0 ]] && return +[[ $EDITOR == "" ]] && return + +zmodload zsh/curses || return + +zcurses init + +function draw_main() { + zcurses clear stdscr + + width=$COLUMNS + + zcurses attr stdscr +bold + + if [[ $width -ge 16 ]]; then + zcurses move stdscr 0 $(($width / 2 - 8)) + zcurses string stdscr "select a filetype" + else + zcurses move stdscr 0 0 + zcurses string stdscr "sel" + fi + + 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)) + done +} + +trap 'draw_main' WINCH + +draw_main + +input="" + +while true; do + zcurses move stdscr $(($#search_strs + 3)) 0 + zcurses clear stdscr bot + zcurses string stdscr "-: $input" + zcurses refresh stdscr + + char="" + sleep 0 + zcurses timeout stdscr 100 + zcurses input stdscr char + + # clear + [[ $char == "" || $char == "" ]] && input="" && continue + + # backspace + [[ $char == "" && $input != "" ]] && input=${input:0:-1} && continue + + # tab complete + if [[ $char == $'\t' ]]; then + seen="false" + + for k in ${(@k)search_strs}; do + [[ $k =~ "^${input}.*$" ]] || continue + [[ $seen == "true" ]] && seen="false" && break + seen="true" + koff=$k + done + + [[ $seen == "true" ]] && input=$koff + + continue + fi + + # select + [[ $char == $'\n' || $char == "" ]] && break + + # add single alphanum + [[ $char =~ "^[a-zA-Z0-9]$" ]] || continue + + input="$input$char" +done + +zcurses end + +[[ $input == "" ]] && return + +file_list=( $(find $@ -regextype posix-extended -regex $search_strs[$input]) ) + +[[ $#file_list -ne 0 ]] && $EDITOR -- $file_list diff --git a/.config/ranger/rifle.conf b/.config/ranger/rifle.conf index 2a4ce83..1e10eb3 100644 --- a/.config/ranger/rifle.conf +++ b/.config/ranger/rifle.conf @@ -51,10 +51,10 @@ ext 1|2|3|4|5|6|7|8|9 = man "$@" # editor for text files mime ^text, label editor = "$EDITOR" -- "$@" -mime ^text, label editor has urxvt, X, flag f = urxvt -e "$EDITOR" "$@" +mime ^text, label weditor X, flag f t = "$EDITOR" -- "$@" !mime ^text, ext xml|html|xhtml|csv|tex|py|pl|rb|sh|php = "$EDITOR" -- "$@" -!mime ^text, ext xml|html|xhtml|csv|tex|py|pl|rb|sh|php, has urxvt, X, flag f = urxvt -e "$EDITOR" "$@" +!mime ^text, ext xml|html|xhtml|csv|tex|py|pl|rb|sh|php, X, flag f t = "$EDITOR" -- "$@" # websites ext x?html?, has firefox, X, flag f = firefox -- "$@" @@ -141,12 +141,16 @@ name ^[mM]akefile$ = make new name ^[mM]akefile$ = make clean name ^[mM]akefile$ = make debug +# open all files of source type +directory, has srcopen = srcopen "$@" +directory, has srcopen, X, flag f t = srcopen "$@" + # music conversion and import directory, has beet = beet imp -t "$1" -# edit -label editor, !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php = "$EDITOR" -- "$@" -label editor, !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php, has urxvt, X, flag f = "urxvt" "-e" "$EDITOR" "$@" +# editor for misc files +!directory, !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php = "$EDITOR" -- "$@" +!directory, !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php, X, flag f t = "$EDITOR" -- "$@" # Send to server & copy to clipboard has send, X = send "$@" |