summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2022-11-18 17:44:33 +0100
committerRobert Günzler <r@gnzler.io>2022-11-18 18:38:20 +0100
commit35b28adfbfda4c6c6058e52c77191e52554795aa (patch)
tree3d051cccb4dc7b9b8b902f472de1378a4e46aa7a
parentbfb1d241d4b98f3ffa3ac891bc0a37befb30b0ad (diff)
bin/fzfez: update
-rwxr-xr-xbin/fzfez162
1 files changed, 104 insertions, 58 deletions
diff --git a/bin/fzfez b/bin/fzfez
index 203927e..4db1516 100755
--- a/bin/fzfez
+++ b/bin/fzfez
@@ -3,6 +3,8 @@
 set -e
 [ -n "$DEBUG" ] && set -x
 
+windowstyle='border-sharp'
+
 exec_hist=/tmp/fzf-interactive_exec-hist
 if [ ! -f "$exec_hist" ]; then
 	touch "$exec_hist"
@@ -18,117 +20,161 @@ if exa --version >/dev/null; then
 fi
 
 case "$1" in
-help|-h|--help)
+help | -h | --help)
 	printf "usage: fzfez [exec|git-log|git-tag|git-branches|rg|fd|vimwiki|*]\n"
-	exit 1 ;;
+	exit 1
+	;;
 
 exec)
-	uniq "$exec_hist" \
-		| grep -v '^$' \
-		| fzf \
+	uniq "$exec_hist" |
+		grep -v '^$' |
+		fzf \
 			--header "${FZFEZ_HEADER:-EXEC:} select or enter a command, {} is \"$2\"" \
 			--bind 'tab:replace-query' \
-			--bind 'enter:print-query' \
-		| tee -a $exec_hist \
-		| sed "s#{}#$2#g"  \
-		| sh -s
+			--bind 'enter:print-query' |
+		tee -a $exec_hist |
+		sed "s#{}#$2#g" |
+		sh -s
 	exit $?
 	;;
 
 _preview)
 	case "$(xdg-mime query filetype "$2")" in
-	inode/directory)                $_ls -la "$2" ;;
-	text/*)                         $_cat "$2" ;;
-	application/javascript)         $_cat "$2" ;;
-	application/x-yaml)             $_cat "$2" ;;
-	application/x-shellscript)      $_cat "$2" ;;
-	application/json)               jq "$2" || $_cat "$2" ;;
-	application/x-compressed-tar)   tar -tvf "$2" ;;
-	application/pdf)                pdftotext "$2" - ;;
-	image/*)                        mediainfo "$2" ;;
-	video/*|audio/*)                mediainfo "$2" ;;
-	*)                              file "$2" ;;
+	inode/directory) $_ls -la "$2" ;;
+	text/*) $_cat "$2" ;;
+	application/javascript) $_cat "$2" ;;
+	application/x-yaml) $_cat "$2" ;;
+	application/x-shellscript) $_cat "$2" ;;
+	application/json) jq "$2" || $_cat "$2" ;;
+	application/x-compressed-tar) tar -tvf "$2" ;;
+	application/pdf) pdftotext "$2" - ;;
+	image/*) mediainfo "$2" ;;
+	video/* | audio/*) mediainfo "$2" ;;
+	*) file "$2" ;;
 	esac
 	;;
 _preview-detach) # invoke for media files
 	case "$(xdg-mime query filetype "$2")" in
-	inode/directory)   swx -f vifm "$2" ;;
-	image/*)           swx -f mvi "$2" ;;
-	video/*|audio/*)   swx -f mpv "$2" ;;
-	application/pdf)   swx -f zathura "$2" ;;
-	text/*)            swx -t ${EDITOR} "$2" ;;
-	*)                 env FZFEZ_HEADER='PREVIEW-DETACH' $0 exec "$2" ;;
+	inode/directory) swx -f vifm "$2" ;;
+	image/*) swx -f imv "$2" ;;
+	video/* | audio/*) swx -f mpv "$2" ;;
+	application/pdf) swx -f zathura "$2" ;;
+	text/*) swx -t ${EDITOR} "$2" ;;
+	*) env FZFEZ_HEADER='PREVIEW-DETACH' $0 exec "$2" ;;
 	esac
 	;;
+_batpreview) # highlights the line matching the query, usage: _batpreview FILENAME QUERY
+	_filename=${2}
+	if [ -z "${_filename}" ]; then
+		exit 1
+	fi
+	_query=${3}
+	if [ -n "${_query}" ]; then
+		_ln=$(grep -n ${_query} "${_filename}" | head -n1 | cut -d: -f1)
+		[ -n "${_ln}" ] && opts="${opts} -H ${_ln}"
+	fi
+	shift 3
+	exec bat ${*} ${opts} "${_filename}"
+	;;
 
+	# | sed 's#^refs/##' \
+	# | sed 's#^remotes/##' \
+	# | sed 's#^heads/##' \
 git-branches)
-	git rev-parse HEAD > /dev/null 2>&1 || exit 1
-	git branch -a --sort=refname --format='%(refname)' \
-		| cut -d' ' -f1 \
-		| sed 's#^refs/##' \
-		| sed 's#^remotes/##' \
-		| sed 's#^heads/##' \
-		| env FZFEZ_HEADER='BRANCHES:' \
+	git rev-parse HEAD >/dev/null 2>&1 || exit 1
+	git branch -a --format='%(refname)' |
+		cut -d' ' -f1 |
+		sort |
+		env FZFEZ_HEADER='BRANCHES: c-o (checkout)' \
 			$0 \
-			--ansi --no-sort --reverse --tac \
+			--ansi --no-sort --tac \
 			--preview 'git log --color=always --oneline --graph --date=short {} | head -${LINES}' \
-			--preview-window right:70% \
-			--bind "ctrl-o:execute(git checkout {})+abort"
+			--preview-window "${windowstyle},right:70%" \
+			--bind "ctrl-o:execute(git checkout {} && git status)+abort"
 	;;
 
 git-tags)
-	git rev-parse HEAD > /dev/null 2>&1 || exit 1
-		git tag --sort -version:refname \
-		| cut -d' ' -f1 \
-		| sed 's#^refs/##' \
-		| sed 's#^remotes/##' \
-		| sed 's#^heads/##' \
-		| env FZFEZ_HEADER='TAGS:' \
+	git rev-parse HEAD >/dev/null 2>&1 || exit 1
+	git tag --sort -version:refname |
+		cut -d' ' -f1 |
+		sed 's#^refs/##' |
+		sed 's#^remotes/##' |
+		sed 's#^heads/##' |
+		env FZFEZ_HEADER='TAGS:' \
 			$0 \
-			--ansi --no-sort --reverse \
+			--ansi --no-sort \
 			--preview 'git show --color=always {} | head -${LINES}' \
-			--preview-window right:70%
+			--preview-window "${windowstyle},right:70%"
 	;;
 
 git-log)
-	git log --color=always --oneline \
-		| env FZFEZ_HEADER='LOG:' \
+	git log --color=always --oneline |
+		env FZFEZ_HEADER='LOG:' \
 			$0 \
 			--ansi --no-sort --reverse \
 			--preview 'echo {} | cut -d\  -f1 | xargs git show --color=always --pretty=full --stat --patch' \
-			--preview-window right:50% \
-		| cut -d' ' -f1 \
-		| xargs -r -i git log -1 --pretty=%H {}
+			--preview-window "${windowstyle},right:50%" |
+		cut -d' ' -f1 |
+		xargs -r -i git log -1 --pretty=%H {}
+	;;
+
+neuron)
+	NOTESDIR=$HOME/.zk
+	rg --no-heading --line-number --with-filename --sort path . "${NOTESDIR}" |
+		env FZFEZ_HEADER='NEURON:' \
+			$0 \
+			--tac -d ':' -n .. \
+			--preview 'bat --style=plain --color=always --highlight-line={2} {1}' \
+			--preview-window "${windowstyle},+{2}-20" |
+		awk -F: "{system(\"${EDITOR}\" \" -c \" \$2 \" \" \$1)}"
 	;;
 
 rg)
 	shift
-	rg --files-with-matches "$@" \
-		| env FZFEZ_HEADER='RG:' \
+	rg --files-with-matches "$@" |
+		env FZFEZ_HEADER='RG:' \
 			$0 \
-			--preview "rg \"$*\" --color=always --no-filename --glob='{}' --context=5 --line-number"
+			--preview "rg \"$*\" --color=always --no-filename --glob='{}' --context=5 --line-number" \
+			--preview-window "${windowstyle}"
 	;;
 
 fd)
 	shift
-	fd "$@" \
-		| env FZFEZ_HEADER='FD: c-o (xdg-open)' \
+	fd "$@" |
+		env FZFEZ_HEADER='FD: c-o (xdg-open)' \
 			$0 \
 			--ansi --reverse \
 			--bind "ctrl-o:execute(xdg-open {})+abort" \
-			--preview-window ':hidden'
+			--preview-window "${windowstyle},hidden"
+	;;
+
+clipboard | cb)
+	shift
+	wl-paste | env FZFEZ_HEADER='CLIPBOARD:' $0
+	;;
+
+mail)
+	shift
+	exec fzf-notmuch "$@"
 	;;
 
 *)
 	fzf \
 		--header "${FZFEZ_HEADER:-FZF:} c-x (exec), ? (preview), c-space (preview-detach), c-s (sort)" \
 		--preview "${0} _preview {}" \
-		--preview-window ':hidden' \
+		--preview-window "${windowstyle},hidden" \
+		--multi \
+		--bind 'enter:replace-query+print-query' \
+		--bind 'ctrl-a:select-all' \
 		--bind '?:toggle-preview' \
 		--bind 'ctrl-s:toggle-sort' \
 		--bind "ctrl-space:execute(${0} _preview-detach {})" \
 		--bind "ctrl-y:yank" \
 		--bind "ctrl-e:execute(${EDITOR} {})+abort" \
 		--bind "ctrl-x:execute(env FZFEZ_HEADER=EXEC: ${0} exec {})+abort" \
-		"$@" ;;
+		--height '50%' \
+		--reverse \
+		$FZFEZ_OPTS \
+		"$@"
+	;;
 esac