Skip to content

Instantly share code, notes, and snippets.

@axel-angel
Last active September 21, 2025 11:56
Show Gist options
  • Select an option

  • Save axel-angel/6f961b3b2c5212c21f97dd0477d353cd to your computer and use it in GitHub Desktop.

Select an option

Save axel-angel/6f961b3b2c5212c21f97dd0477d353cd to your computer and use it in GitHub Desktop.
fzf-jobs-widget for zsh
#!/usr/bin/zsh
j() { # 1 line per job, always
for id cmd in "${(@kv)jobtexts}"; do
echo "${(r:3:)id} $cmd [${jobdirs[$id]}]";
done
}
fzf-jobs-widget() {
local selected num
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
selected=( $(j |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tiebreak=index $FZF_CTRL_R_OPTS +m" $(__fzfcmd)) )
local ret=$?
if [ -z "$selected" ]; then
zle reset-prompt
return $ret
fi;
# from cdg()
local mypath="$(echo "$selected" | sed 's/^.*\[\(.*\)\]$/\1/')";
local mypath="${mypath/#\~/$HOME}";
# from fgg()
local myjobid="$(echo "$selected" | sed -n 's/^\([[:digit:]]\+\).*$/\1/p')";
# check we got valid path and job id
if [ ! -d "$mypath" ] || [[ ! "$myjobid" -gt 0 ]]; then
echo "error invalid path or job id";
zle reset-prompt
return 1;
else
# execute
zle reset-prompt
cd "$mypath";
fg %"$myjobid";
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment