Skip to content

Instantly share code, notes, and snippets.

@nilium
Last active July 7, 2022 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilium/2560594b3c8f5bcf5c9a3b583a71a96f to your computer and use it in GitHub Desktop.
Save nilium/2560594b3c8f5bcf5c9a3b583a71a96f to your computer and use it in GitHub Desktop.
Initial attempt at personal fish configuration, including a port of 'ep'
set -gx PATH ~/bin ~/go/bin $PATH
function fish_user_key_bindings
bind \cz 'fg 2>/dev/null; commandline -f repaint'
end
set -g EP_PATH \
$HOME/src 3 \
$HOME/p 4
set -g EP_FD_ARGS \
-E gists \
-E vim \
-E vendor \
-E node_modules \
-E venv \
-E mod \
-E zig-out \
-E zig-cache \
-E target \
-E bin
function ep
if test (count $argv) -eq 1 -a "$argv[1]" = -
cd -
return $status
end
set candidates (
set wnd 'right:50%'
if test -n "$COLUMNS" -a "$COLUMNS" -lt 100
set wnd 'up:75%'
end
# Requires a bit of tweaking to work with find. The simple equivalent
# would be without account for EP_FD_ARGS:
# find {1} -mindepth 2 -maxdepth {2} -name .git -not -path '*/.*/*' -print -prune
parallel 2>/dev/null \
--line-buffer \
--quote \
--max-args 2 \
fd \
$EP_FD_ARGS \
--prune \
--hidden \
--no-ignore \
--absolute-path \
--max-depth {2} \
--type directory \
--type file \
'^(?:\.git|cpanfile|requirements\.txt|Gemfile|package\.json|go\.mod|cargo\.toml|build\.zig)$|\.gemspec$' {1} \
::: $EP_PATH |
sed -Ee 's#^'{$HOME}'/#~/#;s#/[^/]+$##' |
sort | uniq |
fzf \
--filepath-word \
--select-1 \
--preview "$HOME/.zsh/plugins/ep/preview.zsh {}" \
--preview-window $wnd \
--query "$argv"
)
if not count $candidates &>/dev/null
return 1
end
set sel $candidates[1]
# Reformat selection back into a real path.
if string match '~/*' $sel
set sel "$HOME/$(string sub --start 3 $sel)"
end
if ! test -d $sel
echo "No selection" >&2
return 1
end
cd $sel
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment