Skip to content

Commit

Permalink
add showTODO. reference: sharkdp/bat#2916
Browse files Browse the repository at this point in the history
  • Loading branch information
marslo committed May 2, 2024
1 parent bef996f commit 8b8c40a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .marslo/.marslorc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# FileName : .marslorc
# Author : marslo.jiao@gmail.com
# Created : 2012
# LastChange : 2024-05-02 13:17:00
# LastChange : 2024-05-02 14:59:51
# =============================================================================

export iRCHOME="$HOME/.marslo"
Expand Down Expand Up @@ -145,6 +145,9 @@ test -f "$HOME"/.rbenv/bin/rbenv && eval "$("$HOME
test -f "${FZF_HOME}/shell/key-bindings.bash" && source "${FZF_HOME}/shell/key-bindings.bash"
type -t _fd >/dev/null 2>&1 && complete -F _fd -o nosort -o bashdefault -o default ff ffs
type -t _fzf_opts_completion >/dev/null 2>&1 && complete -F _fzf_opts_completion -o bashdefault -o default vim vimdiff penv imgview fman
# shellcheck disable=SC2015
[[ $(complete -p bat | wc -l) -gt 0 ]] && eval "$(complete -p bat) showTODO" \
|| complete -F _fzf_path_completion -o default -o bashdefault showTODO

# /--------------------------------------------------------------
# __ _
Expand Down
24 changes: 24 additions & 0 deletions .marslo/bin/ifunc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,28 @@ function tcmd() {
eval "${cmd}"
}

# inspired in https://github.com/sharkdp/bat/issues/2916#issuecomment-2061788871
# to enable command auto-completion, add the following line to your .bashrc
# ```
# [[ $(complete -p bat | wc -l) -gt 0 ]] && eval "$(complete -p bat) showTODO" || complete -F _fzf_path_completion -o default -o bashdefault showTODO
# ``
function showTODO() {
local option=''
while [[ $# -gt 0 ]]; do
case "$1" in
-* ) option+="$1 $2 " ; shift 2 ;;
esac
done

while read -r _file; do
# identify language automatically
local lang='';
lang="$(sed -r 's/^.+\.(.+)$/\1/' <<< $_file)";
if [[ "${_file}" = "${lang}" ]]; then
test -x "${_file}" && lang='sh' || lang='groovy';
fi
sed -ne '/TODO:/,/^\s*$/p' "${_file}" | bat -l ${lang} ${option} --file-name="${_file}";
done < <(rg --vimgrep --with-filename 'TODO' --color never | cut -d':' -f1 | uniq)
}

# vim:tabstop=2:softtabstop=2:shiftwidth=2:expandtab:filetype=sh:foldmethod=marker:foldmarker=#\ **************************************************************/,#\ /**************************************************************

0 comments on commit 8b8c40a

Please sign in to comment.