zsh

zsh/fzf/e: add bat preview ยท roosta/etc@b43f758 Free Programming Books โ€“ GoalKicker.com

bindkey -M vicmd

  • check all key bindings

my update for vimmode in zsh

#!/bin/sh
bindkey -v
export KEYTIMEOUT=25
 
if [[ -o menucomplete ]]; then
# Use vim keys in tab complete menu:
bindkey -M menuselect '^h' vi-backward-char
bindkey -M menuselect '^k' vi-up-line-or-history
bindkey -M menuselect '^l' vi-forward-char
bindkey -M menuselect '^j' vi-down-line-or-history
bindkey -M menuselect '^[[Z' vi-up-line-or-history
fi
 
bindkey -v '^?' backward-delete-char
 
# Change cursor shape for different vi modes.
function zle-keymap-select () {
  case $KEYMAP in
      vicmd) echo -ne '\e[1 q';;      # block
      viins|main) echo -ne '\e[5 q';; # beam
  esac
}
zle -N zle-keymap-select
zle-line-init() {
  zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
  echo -ne "\e[5 q"
}
zle -N zle-line-init
echo -ne '\e[5 q' # Use beam shape cursor on startup.
preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.
 
# emacs like keybindings
bindkey -M viins '^A' beginning-of-line
bindkey -M viins '^E' end-of-line
 
# Add text objects for quotes and brackets.
autoload -Uz select-bracketed select-quoted
zle -N select-quoted
zle -N select-bracketed
for m in viopp visual; do
for c in {a,i}{\',\",\`}; do
    bindkey -M $m -- $c select-quoted
done
for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do
    bindkey -M $m -- $c select-bracketed
done
done
 
# Add surround like commands.
autoload -Uz surround
zle -N delete-surround surround
zle -N add-surround surround
zle -N change-surround surround
bindkey -M vicmd cs change-surround
bindkey -M vicmd ds delete-surround
bindkey -M vicmd ys add-surround
bindkey -M visual S add-surround
# Yank to the system clipboard
bindkey -M vicmd U redo
function vi-yank-xclip {
  zle vi-yank
  echo "$CUTBUFFER" | wl-copy
}
 
zle -N vi-yank-xclip
bindkey -M vicmd y vi-yank-xclip
 
bindkey -M vicmd '^[n' run-help
 
bindkey -M viins 'jk' vi-cmd-mode
 
# escape back into normal mode
if [[ -n "${VI_MODE_ESC_INSERT}" ]] then
  bindkey -M viins "${VI_MODE_ESC_INSERT}" vi-cmd-mode
fi
 

man page

You can maintain a separate config directory where you may keep any third-party colour scheme file, or whichever plugin or extra commands you may want, and have

alias nvim-temp='XDG_CONFIG_HOME=<path to new config>/config XDG_DATA_HOME=<path to new config>/data nvim'

and then have export MANPAGER="nvim-temp +Man!" in your rc, and this instance of neovim should start with the plugin you prefer to have while viewing manpages.

I havenโ€™t tried this, though, but itโ€™s worth a shot.

A cool thing about setting the man pager to neovim with export MANPAGER="nvim --clean +Man!"


tumx plugin:

## Fuzzy finder for scroll
 
set -g @plugin 'roosta/tmux-fuzzback'
set -g @fuzzback-popup-size '80%'
 
# set -g @fuzzback-finder 'sk'
 
set -g @fuzzback-bind s
set -g @fuzzback-popup 1
 
# set -g @fuzzback-hide-preview 1
 
set -g @fuzzback-finder-layout 'reverse'
set -g @fuzzback-fzf-colors 'bg+:#100E23,gutter:#323F4E,pointer:#F48FB1,info:#ffe6b3,hl:#F48FB1,hl+:#63f2f1'
set -g @fuzzback-finder-bind 'ctrl-y:execute-silent(echo -n {3..} | wl-copy)+abort'

clipsafe @@

# System clipboard integration
#
# A "safer" copy to clipboard made for Pass and SSH
# Copies only first line and clears clipboard after 30 seconds
 
# safecopy - Copy head of string to clipboard
#
# Usage:
#
#  ssh remote-host [remote command] | safecopy    - copies stdin to local clipboard
#
function clipsafe() {
emulate -L zsh
local file=$1
if which xsel &>/dev/null; then
  if [[ -z $file ]]; then
    head -1 | xsel --clipboard --input
  else
    print "clipsafe: not a string" >&2
    return 1
  fi
  ( sleep 30 ; xsel -bc ) &
else
  print "clipsafe: xsel not installed" >&2
  return 1
fi
}
 
clipsafe "$@"
 
#  vim: set ft=zsh ts=2 sw=2 tw=0 fdm=marker et :
 

etc/conf/zsh/.zsh.d/functions/clipsafe at main ยท roosta/etc

etc/conf/zsh/.zsh.d/fzf.zsh at main ยท roosta/etc

  • need to for reference

fzf with zsh:

# โ”ฌโ”€โ”โ”ฌ โ”โ”Œโ”€โ”โ”Œโ”€โ”โ” โ”ฌ  โ”ฌโ”€โ”oโ”Œโ”โ”โ”ฌโ”€โ”โ”ฌโ”€โ”โ”ฌโ”€โ”
# โ”œโ”€ โ”‚ โ”‚โ”Œโ”€โ”˜โ”Œโ”€โ”˜โ””โ”Œโ”˜โ”€โ”€โ”œโ”€ โ”‚โ”‚โ”‚โ”‚โ”‚ โ”‚โ”œโ”€ โ”‚โ”ฌโ”˜
# โ”†  โ”†โ”€โ”˜โ””โ”€โ”˜โ””โ”€โ”˜ โ”†   โ”†  โ”†โ”†โ””โ”˜โ”†โ”€โ”˜โ”ดโ”€โ”˜โ”†โ””โ”˜
# Options {{{
# Respecting .gitignore, .hgignore, and svn:ignore
# Setting rg as the default source for fzf
export FZF_DEFAULT_COMMAND='rg \
  --colors=path:fg:blue \
  --colors=line:fg:yellow \
  --hidden \
  --smart-case \
  --follow \
  --ignore-file ~/.globalignore \
  --files'
 
export FZF_DEFAULT_OPTS="
--ansi
--color='fg:15,bg:0,hl:5,fg+:15,bg+:235,hl+:13'
--color='info:11,prompt:5,spinner:11,pointer:10,marker:208,header:15'
--bind='alt-k:preview-up,alt-p:preview-up'
--bind='alt-j:preview-down,alt-n:preview-down'
--bind='ctrl-r:toggle-all'
--bind='ctrl-s:toggle-sort'
--bind='ctrl-p:toggle-preview'
--bind='ctrl-a:select-all'
--bind='alt-w:toggle-preview-wrap'
"
# export FZF_COMPLETION_TRIGGER='~~'
 
# To apply the command to CTRL-T as well
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
# export FZF_CTRL_T_OPTS="--preview '(bat -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
#}}}
# Functions {{{
 
# fhist - repeat history
fhist() {
  print -z $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf-tmux +s --tac | sed 's/ *[0-9]* *//')
}
 
fdirs() {
  local dir
  print -rNC1 -- ${(D)dirstack} |
    fzf-tmux \
      --read0 \
      --print0 \
      --ansi \
      --preview 'eval eza --color always -aghl --group-directories-first -F {}' \
      --preview-window 'right:50%' |
    IFS= read -rd '' dir &&
    cd -- ${dir/#\~/$HOME} &&
    zle -I
}
zle -N fdirs # So that it can be used as a shortcut. See keybinds.sh
 
flib() {
  local dir
  dir=$(ls -1 ~/lib | fzf-tmux)
  if [ -n "$dir" ]; then
    cd $HOME/lib/$dir
  else
    return 2
  fi
}
 
# cddir - including hidden directories
cddir() {
  local dir
  dir=$(find ${1:-.} -type d 2> /dev/null | fzf-tmux +m) && cd "$dir"
}
 
# cdfile - cd into the directory of the selected file
cdfile() {
  local file
  local dir
  file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir"
}
 
# Fuzzy match file and open with EDITOR
e() {
  local file
  if [ "$#" -eq 0 ]; then
    file=$(fd -tf --color=always --strip-cwd-prefix | fzf-tmux --ansi --preview 'bat --color=always --style=numbers {}' --preview-window 'right:60%')
    [ -n "$file" ] && sleep 0.1 && vim "$file"
  elif [ "$#" -eq 1 ] && [ -d "$1"  ]; then
    file=$(fd -tf --base-directory="$1" --color=always --strip-cwd-prefix | fzf-tmux --ansi --preview "bat --color=always --style=numbers ${1}/{}" --preview-window 'right:60%')
    echo "$file"
    [ -n "$file" ] && vim -c "cd $1" -- "${1}/$file"
  elif [ "$#" -eq 1 ] && [ -f "$1" ]; then
    vim "$1"
  else
    vim "$@"
  fi
}
 
# Set sudo editor to vim and call sudoedit
# fuzzy edit readonly files
_e() {
  if [ "$#" -ne 0 ]; then
    SUDO_EDITOR="vim" sudoedit $@
  else
    local file
    file=$(fzf-tmux --query="$1")
    [ -n "$file" ] && SUDO_EDITOR="vim" sudoedit "$file"
  fi
}
 
# Open file in notes
o() {
  local file
  file=$(find ~/notes -name '*.md' | fzf -d "/" --query="$1" --with-nth "5..")  &&
    [ -n "$file" ] && vim -c "cd ~/notes" -- "$file"
  }
 
# fsha - get git commit sha
# example usage: git rebase -i `fsha`
fsha() {
  local commits commit
  commits=$(git log --graph --color=always --pretty=oneline --format="%C(auto)%h%d %s %C(black)%C(white)%cr" --abbrev-commit) &&
    commit=$(echo "$commits" | fzf-tmux +s +m -e --ansi) &&
    echo -n $(echo "$commit" | \grep -oe "[0-9a-f]\{5,32\}")
  }
 
# Search apt for query, and install selected package
fapt() {
  local pkg=$(apt-cache search $1 | fzf --no-multi -q $1 --ansi --preview="apt-cache show {1}" | awk '{ print $1 }')
 
  if [[ $pkg ]]; then
    sudo apt-get install $pkg
  fi
}
 
# Search AUR and official repos using yay and install on
# select. Supports multiple selections and preview using yay -Si
faur() {
  local pkg=$(paru -Slq | fzf --multi --query "$1" --preview 'paru -Si {1}')
  if [[ $pkg ]]; then
    paru -S - <<< $pkg
  fi
}
 
# Search with pacman, and install on select. Supports multiple
# selections, and preview using pacman -Si
fpac() {
  local pkg=$(pacman -Ssq | fzf-tmux --multi --query "$1" --preview="pacman -Si {}")
  if [[ $pkg ]]; then
    sudo pacman -S - <<< $pkg
  fi
}
 
falias() {
  local match;
  match=$(bat --color=always --decorations=never ~/.zsh.d/aliases.zsh | fzf-tmux +m --reverse)
  out=$(sed -n "s/^\s*alias [^=]*=[\"']\(.*\)[\"'].*$/\1/p" <<< "$match")
  if [ -n "$out" ]; then
    print -z "$out"
  else
    echo "Not an alias!"
    return 1
  fi
}
 
#}}}
#  vim: set ts=2 sw=2 tw=0 fdm=marker et :

larkery/zsh-histdb: A slightly better history for zsh ไฝฟ็”จ atuin ็ฎก็† zsh ๅ‘ฝไปคๅކๅฒ - Aloxafโ€™s Blog

maniker โ†’ db

Learn X in Y Minutes: Scenic Programming Language Tours

  • explain-command

searching manpages augrmunet:

search -r \b) can also be useful, or spaces/patterns after the word. e.g. to find alias in zshall use alias [.

cargo bropages GitHub - pombadev/bropages: Highly readable supplement to man pages from http://bropages.org. Shows simple, concise examples for commands with syntax highlighting.

All commands

  • bropages =~ tldr, there is also web cheatsheat worth seeing

  • book cheatsheat using sioyek(sync database)

  • sans cheatsheat

  • commandlinefu


asked grok to improve run-help zsh:

# Set HELPDIR if not already set
if (( ! ${+HELPDIR} )); then
  local dir
  for dir in /usr/local/share/zsh/help /usr/share/zsh/${ZSH_VERSION}/help /usr/share/zsh/help; do
    if [[ -d ${dir} ]]; then
      typeset -g HELPDIR=${dir}
      break
    fi
  done
  unset dir
fi
 
# Ensure run-help is not aliased
unalias run-help 2>/dev/null
 
# Define the custom run-help function
function run-help() {
  local cmd=$1
  if [[ -n $cmd ]]; then
    # Check for a specific run-help-<command> function (e.g., run-help-git)
    if declare -f run-help-$cmd > /dev/null; then
      run-help-$cmd $cmd "${@[2,-1]}"
    # Check if the command is a builtin
    elif builtin whence -w $cmd | grep -q 'builtin'; then
      if [[ -n $HELPDIR ]]; then
        # Use Zsh help files with the user's preferred pager or 'more'
        ${=PAGER:-more} $HELPDIR/$cmd
      else
        print "No help available for $cmd"
      fi
    # Check if the command is a function
    elif builtin whence -w $cmd | grep -q 'function'; then
      # Display the function definition
      whence -f $cmd
    # Check if the command is an alias
    elif builtin whence -w $cmd | grep -q 'alias'; then
      # Show the alias expansion
      alias $cmd
    # Assume itโ€™s an external command
    else
      # Try tldr first if itโ€™s installed and has a page for the command
      if command -v tldr &>/dev/null && tldr $cmd &>/dev/null; then
        tldr $cmd
      else
        # Fall back to man if tldr fails or isnโ€™t available
        man $cmd
      fi
    fi
  else
    # No command provided, show general help
    if [[ -n $HELPDIR ]]; then
      ${=PAGER:-more} $HELPDIR/index
    else
      print "No help available"
    fi
  fi
}
 
# Bind the custom run-help to Alt+h and Alt+H
bindkey '^[h' run-help
bindkey '^[H' run-help
 
  • fzf-tab key binding (zshrc)
zstyle ':fzf-tab:*' fzf-bindings 'shift-tab:toggle-all' 'ctrl-e:toggle+down' 'ctrl-y:toggle+up'
 
 

mattmc3/zman: Use fzf to quickly browse Zsh manuals https://www.bash2zsh.com/zsh_refcard/refcard.pdf From Bash to Z Shell: Conquering the Command Line

elkowar/pipr: A tool to interactively write shell pipelines.

 
export FZF_CTRL_T_OPTS="--select-1 --exit-0 --preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | xclip -i)+abort' --header '?:preview C-y:primary'"
if [[ -n ${commands[bfs]} ]]; then
  # /usr/share/fzf/key-bindings.zsh find -> bfs
  export FZF_ALT_C_COMMAND="command bfs -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune -o -type d -print 2> /dev/null | cut -b3-"
  export FZF_CTRL_T_COMMAND="command bfs -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune -o -type f -print -o -type d -print -type l -print 2> /dev/null | cut -b3-"
  export FZF_DEFAULT_COMMAND=$FZF_CTRL_T_COMMAND
fi
 
if [[ -d ~/Util/z.lua && -n ${commands[lua]} ]]; then
  eval "$(lua ~/Util/z.lua/z.lua --init zsh once)"
fi
 
# Environment Modules {{{1
if [[ -f ~/bin/modulecmd.tcl ]]; then
  module() { eval `~/bin/modulecmd.tcl zsh $*`; }
  module use ~/.modules
  module load deno go nim ruby rust #wasm nodejs yarn
fi

689-maskray-dot


cmd spotlight ${{
  apple="$(bfs -color -nohidden -maxdepth 5 -mindepth 1 -exclude \( -name .git -or -name .hg \) -fstype 'sysfs' -prune -o -fstype 'devfs' -prune -o -fstype 'devtmpfs' -prune -o -fstype 'proc' -prune -o -type f -printf '%P\n' -o -type d -printf '%P\n' -o -type l -printf '%P\n' ~ 2>/dev/null | fzf --ansi --reverse --header='Jump to location')"
      if [ -d "$apple" ]; then
          cmd="cd"
      else
          cmd="select"
      fi
      lf -remote "send $id $cmd \"$HOME/$apple\""
}}
map gf :spotlight
 
 
#!/bin/bash
 
# Spawn a new kitty window with lf and spotlight
kitty --title "LF Spotlight" lf -command 'spotlight'
 
# cmd spotlight ${{
#   apple="$(bfs -color -nohidden -maxdepth 6 -mindepth 1 -exclude \( -name .git -or -name .hg \) -fstype 'sysfs' -prune -o -fstype 'devfs' -prune -o -fstype 'devtmpfs' -prune -o -fstype 'proc' -prune -o -type f -printf '%P\n' -o -type d -printf '%P\n' ~ 2>/dev/null | fzf --ansi --reverse --header='Jump to location')"
#       if [ -d "$apple" ]; then
#           cmd="cd"
#       else
#           cmd="select"
#       fi
#       lf -remote "send $id $cmd \"$HOME/$apple\""
# }}
# map gf :spotlight
#
 
 

2025-04-11