Replace fzf with skim

This commit is contained in:
Henrik Lissner 2018-03-23 15:29:50 -04:00
parent d887634ff7
commit 1f94f3ba95
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
19 changed files with 59 additions and 60 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
xdotool search --onlyvisible --classname urxvt-fuzzy windowkill xdotool search --onlyvisible --classname urxvt-fuzzy windowkill
xdotool search --classname urxvt-fuzzy windowmap \ xdotool search --classname urxvt-fuzzy windowmap \
|| urxvt -name urxvt-fuzzy -geometry 80x18 -e $SHELL -c fzf-apps || urxvt -name urxvt-fuzzy -geometry 80x18 -e $SHELL -c sk-apps

View file

@ -1,7 +1,7 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
# #
# Opens fzf-pass in a transient popup window and temporary tmux session, # Opens sk-pass in a transient popup window and temporary tmux session,
# recreating this window if necessary. # recreating this window if necessary.
# #
@ -24,6 +24,6 @@ bspc monitor -f primary
urxvt -name urxvt-fuzzy \ urxvt -name urxvt-fuzzy \
-geometry 100x16 \ -geometry 100x16 \
-e $SHELL \ -e $SHELL \
-c "fzf-pass $@ $url" -c "sk-pass $@ $url"
[[ -n $win ]] && xdotool windowactivate $win [[ -n $win ]] && xdotool windowactivate $win

View file

@ -5,8 +5,7 @@ A shell script that converts one currency to another.
Usage: shekel [-rh] AMOUNT FROM TO [TO ...] Usage: shekel [-rh] AMOUNT FROM TO [TO ...]
FROM and TO are either currency codes or a fuzzy substring (requires iterfzf and FROM and TO are currency codes.
fzf).
Examples: Examples:
shekel 200 USD CAD shekel 200 USD CAD

View file

@ -1,10 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Find the correct spelling of a word. Uses (and requires) fzf to select the # Find the correct spelling of a word. Uses (and requires) skim to select the
# correct word. This output can be piped to something like dict to find # correct word. This output can be piped to something like dict to find
# definitions/synonyms. # definitions/synonyms.
# #
# Requires: aspell, fzf # Requires: aspell, skim
# Usage: spell mispeling # Usage: spell mispeling
# Example: dict $(spell mispeling) # Example: dict $(spell mispeling)
@ -13,8 +13,8 @@ if [[ "$result" == '*' ]]; then
echo "$@" echo "$@"
else else
words=$(echo "$result" | sed $'s/[:,] /\\\n/g' | tail -n +2) words=$(echo "$result" | sed $'s/[:,] /\\\n/g' | tail -n +2)
if (( $(wc -l <<< "$words") > 1 )) && command -v 'fzf' >/dev/null; then if (( $(wc -l <<< "$words") > 1 )) && command -v sk >/dev/null; then
fzf <<< "$words" sk <<< "$words"
else else
echo "$words" echo "$words"
fi fi

View file

@ -1,7 +1,7 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
# Performs an online search. Uses the last used provider, otherwise prompts for # Performs an online search. Uses the last used provider, otherwise prompts for
# one with fzf. # one with skim.
provider="$1"; shift provider="$1"; shift
query="$*" query="$*"
@ -19,7 +19,7 @@ providers+=('Youtube' 'https://youtube.com/results?aq=f&oq=&search_query=%s')
providers+=('Wolfram alpha' 'https://wolframalpha.com/input/?i=%s') providers+=('Wolfram alpha' 'https://wolframalpha.com/input/?i=%s')
providers+=('Wikipedia' 'https://wikipedia.org/search-redirect.php?language=en&go=Go&search=%s') providers+=('Wikipedia' 'https://wikipedia.org/search-redirect.php?language=en&go=Go&search=%s')
pick=$(printf "%s\n" "${(@k)providers}" | fzf --query="$provider" --prompt='provider > ' -1 -0) pick=$(printf "%s\n" "${(@k)providers}" | sk --query="$provider" --prompt='provider > ' -1 -0)
if [[ -z $pick ]]; then if [[ -z $pick ]]; then
>&2 echo 'No provider selected. Aborting.' >&2 echo 'No provider selected. Aborting.'
exit 1 exit 1

View file

@ -1,5 +0,0 @@
alias fgcf='noglob git commit -S --fixup `fzf-git-sha`'
alias fgl=fzf-git-log
alias bm=fzf-browser-bookmarks
alias hist=fzf-browser-history

View file

@ -1,11 +0,0 @@
#!/usr/bin/env bash
#
# Select and play a song from the current playlist (using fzf)
#
set -e
song=$(mpc -f "%position%) %artist% - %title%" playlist)
song_index=$(fzf --query="$1" --select-1 --exit-0 --prompt='play > ' <<<"$song" | sed -n 's/^\([0-9]\+\)).*/\1/p')
[[ -n $song_index ]] && mpc -q play "$song_index"

View file

@ -1 +0,0 @@
export FZF_DEFAULT_OPTS='--reverse --color=16,fg+:2,bg+:0,hl:4,hl+:4,prompt:4,pointer:8'

View file

@ -3,9 +3,9 @@ source ${0:A:h}/../../deploy
install() { install() {
case $(_os) in case $(_os) in
macos) brew install fzf ;; macos) brew install sbdchd/skim/skim ;;
arch) sudo pacman --needed --noconfirm -S fzf ;; arch) pacaur --needed --noconfirm -S skim ;;
debian) sudo apt-get install -y fzf ;; debian) sudo apt-get install -y skim ;;
esac esac
} }

5
shell/sk/aliases.zsh Normal file
View file

@ -0,0 +1,5 @@
alias skgcf='noglob git commit -S --fixup `skim-git-sha`'
alias skgl=skim-git-log
alias bm=skim-browser-bookmarks
alias hist=skim-browser-history

View file

@ -1,20 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Uses fzf as an application launcher. # Uses skim as an application launcher.
# #
# Requires: fzf, lnch # Requires: skim, lnch
_do_sk() { sk --prompt='open > '; }
FZF_DEFAULT_OPTS="--prompt='open > ' $FZF_DEFAULT_OPTS"
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
cmd=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null | sort -u | fzf) cmd=$(find -L {,~}/Applications -iname '*.app' -maxdepth 2 -type d 2>/dev/null | sort -u | _do_sk)
[[ -n $cmd ]] && open "$cmd" [[ -n $cmd ]] && open "$cmd"
;; ;;
linux*) linux*)
cmd=$(echo -n "$PATH" | xargs -d: -I{} -r -- find -L {} -maxdepth 1 -mindepth 1 -type f -executable -printf '%P\n' 2>/dev/null | sort -u | fzf) cmd=$(echo -n "$PATH" | xargs -d: -I{} -r -- find -L {} -maxdepth 1 -mindepth 1 -type f -executable -printf '%P\n' 2>/dev/null | sort -u | _do_sk)
if [[ -z $cmd ]]; then if [[ -z $cmd ]]; then
exit exit
elif [[ $cmd == fzf-* ]]; then elif [[ $cmd == sk-* ]]; then
$cmd $cmd
elif ! command -v lnch >/dev/null; then elif ! command -v lnch >/dev/null; then
>&2 echo "lnch not installed, run 'go get github.com/oem/lnch'" >&2 echo "lnch not installed, run 'go get github.com/oem/lnch'"

View file

@ -1,14 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Interactively select (in fzf) bookmarks to open from Firefox or # Interactively select (in skim) bookmarks to open from Firefox or
# Chrome/Chromium (depends on $BROWSER). Should work on Linux and MacOS. # Chrome/Chromium (depends on $BROWSER). Should work on Linux and MacOS.
# #
# requires: sqlite3, jq (if you use chrome/chromium) # requires: sqlite3, jq (if you use chrome/chromium)
[[ $OSTYPE == linux* ]] && open='xdg-open' || open='open' [[ $OSTYPE == linux* ]] && open='xdg-open' || open='open'
_do_fzf() { _do_sk() {
for url in $(awk -F "$1" '{printf "%s, %s\n", $1, $2}' | fzf --prompt='bookmarks > ' --multi | sed 's#.*\(https*://\)#\1#'); do for url in $(awk -F "$1" '{printf "%s, %s\n", $1, $2}' | skim --prompt='bookmarks > ' --multi | sed 's#.*\(https*://\)#\1#'); do
$open "$url" & $open "$url" &
done done
} }
@ -22,7 +22,7 @@ case ${BROWSER:-firefox} in
"SELECT DISTINCT mb.title, mp.url FROM moz_bookmarks mb \ "SELECT DISTINCT mb.title, mp.url FROM moz_bookmarks mb \
INNER JOIN moz_places mp ON mp.id = mb.fk \ INNER JOIN moz_places mp ON mp.id = mb.fk \
WHERE mb.type = 1 AND mb.title IS NOT NULL \ WHERE mb.type = 1 AND mb.title IS NOT NULL \
ORDER BY mp.frecency DESC" | _do_fzf "$sep" ORDER BY mp.frecency DESC" | _do_sk "$sep"
break break
fi fi
done done
@ -33,7 +33,7 @@ case ${BROWSER:-firefox} in
if [[ -f "$dir/Bookmarks" ]]; then if [[ -f "$dir/Bookmarks" ]]; then
jq -r '.. | [.name, .url]? | @tsv' "$dir/Bookmarks" | \ jq -r '.. | [.name, .url]? | @tsv' "$dir/Bookmarks" | \
sed '/^[ \t]*$/d;/\t$/d;/\tchrome:\/\//d' | \ sed '/^[ \t]*$/d;/\t$/d;/\tchrome:\/\//d' | \
_do_fzf "\t" _do_sk "\t"
break break
fi fi
done done

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Interactively select (in fzf) an url from Firefox/Chrome/Chromium history to # Interactively select (in skim) an url from Firefox/Chrome/Chromium history to
# open in your browser (depends on $BROWSER). Should work on Linux and MacOS. # open in your browser (depends on $BROWSER). Should work on Linux and MacOS.
# #
# requires: sqlite3 # requires: sqlite3
@ -8,8 +8,8 @@
sep='{{::}}' sep='{{::}}'
[[ $OSTYPE == linux* ]] && open='xdg-open' || open='open' [[ $OSTYPE == linux* ]] && open='xdg-open' || open='open'
_do_fzf() { _do_skim() {
for url in $(awk -F "$sep" '{printf "%s, %s\n", $1, $2}' | fzf --prompt='history > ' --multi | sed 's#.*\(https*://\)#\1#'); do for url in $(awk -F "$sep" '{printf "%s, %s\n", $1, $2}' | skim --prompt='history > ' --multi | sed 's#.*\(https*://\)#\1#'); do
$open "$url" & $open "$url" &
done done
} }
@ -21,7 +21,7 @@ case ${BROWSER:-firefox} in
sqlite3 -separator $sep "$dir/places.sqlite" \ sqlite3 -separator $sep "$dir/places.sqlite" \
"SELECT DISTINCT title, url FROM moz_places \ "SELECT DISTINCT title, url FROM moz_places \
WHERE title IS NOT NULL \ WHERE title IS NOT NULL \
ORDER BY last_visit_date DESC" | _do_fzf ORDER BY last_visit_date DESC" | _do_skim
break break
fi fi
done done
@ -32,7 +32,7 @@ case ${BROWSER:-firefox} in
cp -f "$dir/History" "/tmp/_h" cp -f "$dir/History" "/tmp/_h"
sqlite3 -separator $sep "/tmp/_h" \ sqlite3 -separator $sep "/tmp/_h" \
"SELECT substr(title, 1, $((COLUMNS / 3))), url \ "SELECT substr(title, 1, $((COLUMNS / 3))), url \
FROM urls ORDER BY last_visit_time DESC" | _do_fzf FROM urls ORDER BY last_visit_time DESC" | _do_skim
break break
fi fi
done done

View file

@ -1,9 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
git log --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" | \ git log --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" | \
fzf --ansi --no-sort --tiebreak=index --bind=ctrl-s:toggle-sort \ sk --ansi --no-sort --tiebreak=index --bind=ctrl-s:toggle-sort \
--bind "ctrl-m:execute: --bind "ctrl-m:execute:
(grep -o '[a-f0-9]\{7\}' | head -1 | (grep -o '[a-f0-9]\{7\}' | head -1 |
xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF' xargs -I % sh -c 'git show --color=always % | less -R') << 'SK-EOF'
{} {}
FZF-EOF" SK-EOF"

View file

@ -3,9 +3,9 @@
# Retrieves a git commit's SHA, useful for a variety of git commands. # Retrieves a git commit's SHA, useful for a variety of git commands.
# #
# Examples: # Examples:
# + git checkout `fzf-git-sha` # + git checkout `sk-git-sha`
# + git commit --fixup `fzf-git-sha` # + git commit --fixup `sk-git-sha`
commits=$(git log --color=always --abbrev-commit --reverse --format="%C(auto)%h%d %s %C(black)%C(bold)%cr") && commits=$(git log --color=always --abbrev-commit --reverse --format="%C(auto)%h%d %s %C(black)%C(bold)%cr") &&
commit=$(echo "$commits" | fzf --tac +s +m -e --ansi) && commit=$(echo "$commits" | sk --tac --no-sort -e --ansi) &&
echo -n $(echo "$commit" | sed "s/ .*//") echo -n $(echo "$commit" | sed "s/ .*//")

View file

@ -2,7 +2,7 @@
# Interactively select a process to kill. # Interactively select a process to kill.
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}') pid=$(ps -ef | sed 1d | sk -m | awk '{print $2}')
if [[ -n $pid ]]; then if [[ -n $pid ]]; then
xargs kill -${1:-9} <<< "$pid" xargs kill -${1:-9} <<< "$pid"

11
shell/sk/bin/sk-mpc Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bash
#
# Select and play a song from the current playlist (using skim)
#
set -e
song=$(mpc -f "%position%) %artist% - %title%" playlist)
song_index=$(sk --query="$1" --select-1 --exit-0 --prompt='play > ' <<<"$song" | sed -n 's/^\([0-9]\+\)).*/\1/p')
[[ -n $song_index ]] && mpc -q play "$song_index"

View file

@ -2,9 +2,9 @@
# #
# Prompts for a pass entry, then for a specific field. Similar to passmenu, but # Prompts for a pass entry, then for a specific field. Similar to passmenu, but
# uses fzf, and can resume from a previous session. # uses sk, and can resume from a previous session.
# #
# Example: fzf-pass [RESUME] # Example: sk-pass [RESUME]
# #
set -e set -e
@ -18,13 +18,12 @@ url=$@
LAST_ENTRY_FILE=/tmp/_upm LAST_ENTRY_FILE=/tmp/_upm
if [[ -n $resume && -f $LAST_ENTRY_FILE ]]; then if [[ -n $resume && -f $LAST_ENTRY_FILE ]]; then
entry="$(<$LAST_ENTRY_FILE)" entry="$(<$LAST_ENTRY_FILE)"
last=1
else else
prefix=${PASSWORD_STORE_DIR-~/.password-store} prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg ) password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" ) password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" ) password_files=( "${password_files[@]%.gpg}" )
entry=$(printf "%s\n" "${password_files[@]}" | fzf --query="$url" --prompt='pass > ') entry=$(printf "%s\n" "${password_files[@]}" | sk --query="$url" --prompt='pass > ')
fi fi
if [[ -z $entry ]]; then if [[ -z $entry ]]; then
@ -36,7 +35,7 @@ echo "$entry" >/tmp/_upm
secrets="$(pass show "$entry")" secrets="$(pass show "$entry")"
if [[ -n $secrets ]]; then if [[ -n $secrets ]]; then
fields=$(awk -F': ' 'NR>1 && !/^otpauth:/ {print $1}' <<<"$secrets") fields=$(awk -F': ' 'NR>1 && !/^otpauth:/ {print $1}' <<<"$secrets")
field=$(printf "password\n%s\notp\n" "${fields[@]}" | fzf --prompt="pass ($entry) > ") field=$(printf "password\n%s\notp\n" "${fields[@]}" | sk --prompt="pass ($entry) > ")
case $field in case $field in
password) printf "%s" "$(head -n1 <<<"$secrets")" ;; password) printf "%s" "$(head -n1 <<<"$secrets")" ;;
otp) printf "%s" "$(pass otp "$entry")" ;; otp) printf "%s" "$(pass otp "$entry")" ;;

1
shell/sk/env.zsh Normal file
View file

@ -0,0 +1 @@
export SKIM_DEFAULT_OPTIONS='--reverse --color=16,fg+:2,bg+:0,hl:4,hl+:4,prompt:4,pointer:8'