--- /gnu/store/2hsg15n644f0glrcbkb1kqknmmqdar03-zsh-5.8/share/zsh/5.8/functions/sticky-note 1970-01-01 01:00:01.000000000 +0100 +++ /home/ben/.oh-my-zsh/custom/autoload/sticky-note 2021-05-02 23:45:17.021881434 +0100 @@ -49,7 +49,7 @@ # I encourage all you creative people to contribute enhancements ... emulate -LR zsh -setopt nobanghist extendedhistory histignoredups +setopt nobanghist extendedhistory histignoredups noflowcontrol extendedglob local STICKYFILE=${STICKYFILE:-$HOME/.zsticky} local STICKYSIZE=${STICKYSIZE:-1000} @@ -72,19 +72,47 @@ bindkey -M sticky-vicmd ZZ accept-line fi -[[ "$1" == -b ]] && return 0 +if [[ "$*" == *-h* ]]; then + print "Usage: sticky-note [OPTION]... +Where [OPTION]s can be: + + -h display this help and exit + -l list existing sticky notes + -b install keymaps & keybindings, and exit + -c COL make sticky note a certain colour (ignored with -l option) + -B make sticky note blink (ignored with -l option) + +With no option a new sticky note is prompted for, with colour specified +by the \"theme\" zstyle for the \":sticky-note\" context" + return 0 +fi + +[[ "$1" == *-b* ]] && return 0 # Look up color theme local -A theme (($+bg && $+fg)) || { autoload -Uz colors; colors } + zstyle -m :sticky-note theme '*' || { zstyle :sticky-note theme bg yellow fg black } zstyle -a :sticky-note theme theme -(( ${+bg[$theme[bg]]} )) && theme[bg]=$bg[$theme[bg]] (( ${+fg[$theme[fg]]} )) && theme[fg]=$fg[$theme[fg]] +(( ${+bg[$theme[bg]]} )) && theme[bg]=$bg[$theme[bg]] (( ${+theme[color]} )) || theme[color]=$theme[bg]$theme[fg] (( ${+theme[reset]} )) || theme[reset]=$reset_color +# If -c option is supplied use as background colour +if [[ "$*" == *-c\ [a-z]##* ]]; then + theme[newcolor]="$bg[${*//(#b)*-c ([a-z]#)*/$match}]${theme[fg]}" +else + theme[newcolor]=$theme[color] +fi +# blink text if -B option supplied +if [[ "$*" == *-B* ]]; then + theme[newcolor]+="$(echoti blink)" +fi + +local fcopts="${${${${@//-B}//-c #[a-z]#}## #}%% #}" # If invoked as a widget, behave a bit like run-help if zle @@ -96,7 +124,7 @@ echoti sc echoti home print -nr "$theme[color]" - fc -l "${@:--1}" | while read -r sticky; do print -- "$sticky"; done + fc -l "${fcopts:--1}" | while read -r sticky; do print -b -- "$sticky"; done print -nr "$theme[reset]" echoti rc elif [[ $CONTEXT = (cont|select|vared) ]] @@ -120,19 +148,20 @@ then print -nr "$theme[color]" # Use read/print loop to interpolate "\n" in history lines - fc -f "$@" | while read -r sticky; do print -- "$sticky"; done + fc -f "${fcopts}" | while read -r sticky; do print -b -- "$sticky"; done print -nr "$theme[reset]" return 0 fi # Edit a new sticky note and add it to the stickyfile -while vared -h -p "%{$theme[color]%}" -M sticky -m sticky-vicmd sticky +while vared -h -e -p "%{$theme[newcolor]%}" -M sticky -m sticky-vicmd sticky do { - [[ -n "$sticky" ]] && print -s -- "$sticky" + [[ -n "$sticky" ]] && print -s -- "${theme[newcolor]}$sticky${theme[color]}\e[25m" } always { (( TRY_BLOCK_ERROR = 0 )) } && break echo -n -e '\a' done return 0 +