commit 1f5e5723a838dd49a48d1eb5c225ce718b5f86bf
parent 4fa9b72aae49be831d98d2f2c4b2a75f97d5f658
Author: William Casarin <jb55@jb55.com>
Date: Thu, 12 Nov 2020 17:03:10 -0800
fuzz search files
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
10 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/bin/fuzz-edit-command b/bin/fuzz-edit-command
@@ -1,2 +1,4 @@
#!/usr/bin/env bash
-file=$(cutt -f3 $HOME/dotfiles/commands | $FUZZER) && echo "sedit $file"
+set -e
+res=$(<$HOME/dotfiles/commands $FUZZER)
+echo "sedit $(cutt -f3 <<<$res)"
diff --git a/bin/fuzz-edit-file b/bin/fuzz-edit-file
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -e
-file=$(rg --files | $FUZZER | xargs readlink -f)
-echo $EDITOR \"$file\"
+file=$(rg --files | $FUZZER)
+echo $EDITOR \"$(readlink -f $file)\"
diff --git a/bin/fuzz-ident b/bin/fuzz-ident
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+echo "$@"
diff --git a/bin/fuzz-run-command b/bin/fuzz-run-command
@@ -1,19 +1,30 @@
#!/usr/bin/env bash
function runner() {
+ local prefix
local res
local get_cmd
local fhist
local cmd
- res=$($FUZZER --select-1 --exit-0 -q ^"$@" < $HOME/dotfiles/commands) &&
+ if [ -n "$1" ]; then
+ prefix="$1"
+ shift
+ fi
+ res=$($FUZZER +i --select-1 --exit-0 -q ^"$prefix" < $HOME/dotfiles/commands) &&
get_cmd=$(cutt -f3 <<<"$res") || return
fhist="$HOME/.fuzzhist"
touch "$fhist"
- cmd="$($get_cmd)"
+ export ORIG_OPTS="$FZF_DEFAULT_OPTS"
+ export INITIAL_QUERY="$@"
+ if [ "$@" ]; then
+ export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS -q '$@'"
+ fi
+ cmd="$(eval $get_cmd)"
if [ -n "$cmd" ]; then
echo "$cmd" >> "$fhist"
eval $cmd
fi
+ export FZF_DEFAULT_OPTS="$ORIG_OPTS"
}
runner "$@"
diff --git a/bin/fuzz-search-files b/bin/fuzz-search-files
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+set -e
+res="$(search-files)"
+echo $EDITOR $res
diff --git a/bin/fuzz-show-script b/bin/fuzz-show-script
@@ -1,2 +1,4 @@
#!/usr/bin/env sh
-file="$(ls -1 "$HOME/bin" | $FUZZER)" && cat "$HOME/bin/$file"
+set -e
+file="$(ls -1 "$HOME/bin" | $FUZZER)"
+echo cat \"$HOME/bin/$file\"
diff --git a/bin/fuzz-systemd-start b/bin/fuzz-systemd-start
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+set -e
+service=$(systemctl list-units --user --type=service | awk '{print $1}' | sort -u | $FUZZER)
+echo systemctl start --user -u "$service"
diff --git a/bin/fuzz-tag-jump b/bin/fuzz-tag-jump
@@ -1,2 +1,6 @@
#!/usr/bin/env bash
-<tags sed -En '/^!/d;s,^([^\t]+).*,\1,p' | sort -u | $FUZZER
+set -e
+if [ -f tags ]; then
+ file="$(<tags sed -En '/^!/d;s,^([^\t]+).*,\1,p' | sort -u | $FUZZER)"
+ echo $EDITOR \"$(readlink -f "$file")\"
+fi
diff --git a/dotfiles/.zshrc b/dotfiles/.zshrc
@@ -21,8 +21,8 @@ zstyle ':completion:*:directory-stack' list-colors '=(#b) #([0-9]#)*( *)==95=38;
# short ESC delay
export KEYTIMEOUT=1
+
bindkey "^R" history-incremental-search-backward
-bindkey "^F" history-incremental-search-forward
# history settings
export HISTSIZE=50000
@@ -88,6 +88,13 @@ export BARI=$HOME/Dropbox/shared/bari
ALIASES="$HOME/.bash_aliases"
[ -e "$ALIASES" ] && source "$ALIASES"
+runthefuzzyo_hist () { f h }
+runthefuzzyo () { f "$@" }
+zle -N runthefuzzyo
+zle -N runthefuzzyo_hist
+bindkey "^F" runthefuzzyo
+bindkey "^H" runthefuzzyo_hist
+
DIRCOLORS="$HOME/.dircolors"
[ -e "$DIRCOLORS" ] && eval "$(dircolors -b "$DIRCOLORS")"
diff --git a/dotfiles/commands b/dotfiles/commands
@@ -1,5 +1,13 @@
-cd find directory fuzz-cd-dirname cd
-efcl edit fuzz command list fuzz-edit-command-list
-efc edit fuzz command fuzz-edit-command
+cd find directory fuzz-cd-dirname
+ef edit file fuzz-edit-file
+eFl edit fuzz command list fuzz-edit-command-list
+eFc edit fuzz command fuzz-edit-command
+sFc show fuzz command fuzz-show-fuzz-command
ec edit commands fuzz-edit-scripts
sc show command fuzz-show-script
+sf search files fuzz-search-files
+Sr systemd restart fuzz-systemd-restart
+Ss systemd start fuzz-systemd-start
+SS systemd stop fuzz-systemd-stop
+h run fuzz hist fuzz-run-hist
+tj tag jump fuzz-tag-jump