Last active
September 30, 2015 03:21
-
-
Save alphapapa/69dbe9d61f5fa127eb11 to your computer and use it in GitHub Desktop.
Fish functions and bindings for finding directories and files with Percol and locate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/fish | |
set -g percolOptions --prompt-bottom --result-bottom-up | |
# This is simply too slow right now, so using Bash instead | |
function onlyDirs | |
while read dir | |
test -d $dir | |
and echo $dir | |
end | |
end | |
function _percol_find_cd | |
set tempfile (mktemp) | |
find . -type d | xn ls -ldt | printlink.py | percol --query (commandline) $percolOptions > $tempfile | |
and cd (cat $tempfile) | |
and commandline '' | |
commandline -f repaint | |
rm -f $tempfile | |
end | |
function _percol_locate_cd | |
set tempfile (mktemp) | |
set argv $argv (commandline -o) | |
locate -eiA $argv | onlydirs | xn ls -dtr | percol $percolOptions > $tempfile | |
and cd (cat $tempfile) | |
and commandline '' | |
and commandline -f repaint | |
rm -f $tempfile | |
end | |
function _percol_locate_cd_homedir | |
_percol_locate_cd $HOME | |
end | |
function _percol_locate_cd_cwd | |
_percol_locate_cd (pwd) | |
end | |
function _percol_locate_file | |
set tempfile (mktemp) | |
set argv $argv (commandline -o) | |
# Filter out backup files | |
locate -eiA $argv | egrep -v '~$' | xn ls -tr | percol $percolOptions > $tempfile | |
and commandline (cat $tempfile) | |
and commandline -f repaint | |
and commandline --cursor 0 | |
rm -f $tempfile | |
end | |
function _percol_history | |
set tempfile (mktemp) | |
history | percol --query (commandline) --prompt-bottom --result-bottom-up > $tempfile | |
and commandline (cat $tempfile) | |
and commandline -f repaint | |
rm -f $tempfile | |
end | |
function _percol_saved_commands | |
set tempfile (mktemp) | |
percol --query (commandline) $percolOptions ~/.saved-commands > $tempfile | |
and commandline (cat $tempfile) | |
commandline -f repaint | |
rm -f $tempfile | |
end | |
function _percol_bind_keys | |
bind \ec _percol_find_cd | |
bind \el _percol_locate_cd_cwd | |
bind \eL _percol_locate_cd_homedir | |
bind \e\cl _percol_locate_cd | |
bind \e\cf _percol_locate_file | |
bind \cs _percol_saved_commands | |
bind \cr _percol_history | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment