Skip to content

Instantly share code, notes, and snippets.

@nilium
Last active November 12, 2023 23:41
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/f8531e71f1bac92fbf3d4d74cccddc6b to your computer and use it in GitHub Desktop.
Save nilium/f8531e71f1bac92fbf3d4d74cccddc6b to your computer and use it in GitHub Desktop.
Latest version of ep for fish
#!/usr/bin/env bash
lscmd=(ls -lh)
if command -v &>/dev/null tree; then
lscmd=(
tree
-I gists
-I vim
-I vendor
-I node_modules
-I venv
-I mod
-I zig-out
-I zig-cache
-I target
-I bin
--
)
fi
for dir; do
echo -e "\e[1;4;38;5;45m${dir}\e[0m"
echo
if [[ "$dir" == '~/'* ]]; then
dir="$HOME/${dir#'~/'}"
fi
if [[ -d "$dir/.git" ]]; then
git -C "$dir" -c color.status=always status -uno
echo
echo
git -C "$dir" log --graph -n10 --color
elif [[ -d "$dir/README.md" ]]; then
cat "$dir/README.md"
elif [[ -d "$dir/README.adoc" ]]; then
cat "$dir/README.adoc"
elif [[ -d "$dir/README.rst" ]]; then
cat "$dir/README.rst"
elif [[ -d "$dir/README.txt" ]]; then
cat "$dir/README.txt"
elif [[ -d "$dir/README" ]]; then
cat "$dir/README"
else
"${lscmd[@]}" "$dir"
fi
done
set -g EP_PATH \
$HOME/src 4 \
$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 \
-E *.archive
set -g EP_FD_PATTERN \
'^(?:\.git|cpanfile|requirements\.txt|Gemfile|package\.json|go\.mod|[Cc]argo\.toml|build\.zig|rebar\.config)$|\.gemspec$'
function ep
argparse \
--name=ep \
--stop-nonopt \
--ignore-unknown \
'p/print' \
'1/first' \
-- $argv
if test (count $argv) -eq 1 -a "$argv[1]" = -
cd -
return $status
end
set printonly (test -n "$_flag_print"; echo $status)
set fzfquery query
if test -n "$_flag_first"
set fzfquery filter
end
set candidates (
set wnd 'right:57%'
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 \
$EP_FD_PATTERN \
{1} \
::: $EP_PATH |
sed -Ee 's#^'{$HOME}'/#~/#;s#/[^/]+$##' |
sort | uniq |
fzf \
--filepath-word \
--select-1 \
--preview "$HOME/.config/fish/ep/_ep-preview {}" \
--preview-window $wnd \
--$fzfquery "$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 &>/dev/null
set sel "$HOME/$(string sub --start 3 $sel)"
end
if ! test -d $sel
echo "No selection" >&2
return 1
end
if test $printonly -eq 0
echo $sel
return 0
end
cd $sel
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment