diff options
Diffstat (limited to 'fedora/.local')
| -rwxr-xr-x | fedora/.local/bin/bat | bin | 0 -> 6910848 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/bmshortcuts (renamed from fedora/.local/bin/shortcuts) | 22 | ||||
| -rwxr-xr-x | fedora/.local/bin/bookmarks | 211 | ||||
| -rwxr-xr-x | fedora/.local/bin/chafa | bin | 0 -> 7175232 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/eza | bin | 0 -> 2491296 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/fzf | bin | 0 -> 4411544 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/fzf-preview.sh | 86 | ||||
| -rwxr-xr-x | fedora/.local/bin/fzf-tmux | 257 | ||||
| -rwxr-xr-x | fedora/.local/bin/fzffiles | 99 | ||||
| -rwxr-xr-x | fedora/.local/bin/fzffns | 74 | ||||
| -rwxr-xr-x | fedora/.local/bin/fzfpass | 88 | ||||
| -rwxr-xr-x | fedora/.local/bin/imgcat | 274 | ||||
| -rwxr-xr-x | fedora/.local/bin/lastfiles (renamed from fedora/.local/bin/lastnvim) | 27 | ||||
| -rwxr-xr-x | fedora/.local/bin/openfiles | 12 | ||||
| -rwxr-xr-x | fedora/.local/bin/restartvim (renamed from fedora/.local/bin/restartnvim) | 8 | ||||
| -rwxr-xr-x | fedora/.local/bin/rg | bin | 0 -> 5445512 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/rga | bin | 0 -> 6772816 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/rga-fzf | bin | 0 -> 2425600 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/rga-fzf-open | bin | 0 -> 2429728 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/rga-preproc | bin | 0 -> 8071664 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/sesh | bin | 0 -> 8851145 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/sessionizer | 36 | ||||
| -rwxr-xr-x | fedora/.local/bin/tmuxopen | 42 | ||||
| -rwxr-xr-x | fedora/.local/bin/ya | bin | 0 -> 3306160 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/yazi | bin | 0 -> 17066736 bytes | |||
| -rwxr-xr-x | fedora/.local/bin/zoxide | bin | 0 -> 1253856 bytes |
26 files changed, 973 insertions, 263 deletions
diff --git a/fedora/.local/bin/bat b/fedora/.local/bin/bat Binary files differnew file mode 100755 index 0000000..f9846c7 --- /dev/null +++ b/fedora/.local/bin/bat diff --git a/fedora/.local/bin/shortcuts b/fedora/.local/bin/bmshortcuts index ab5e69d..af4ad58 100755 --- a/fedora/.local/bin/shortcuts +++ b/fedora/.local/bin/bmshortcuts @@ -10,9 +10,15 @@ zsh_named_dirs="${XDG_CONFIG_HOME:-${HOME}/.config}/shell/zshnameddirrc" command -v lf && lf_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/lf/shortcutrc" || lf_shortcuts="/dev/null" command -v vim && vim_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/vim/shortcuts.vim" || vim_shortcuts="/dev/null" command -v nvim && nvim_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/nvim/shortcuts.lua" || nvim_shortcuts="/dev/null" -command -v yazi && yazi_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/yazi/keymap.toml" || yazi_shortcuts="/dev/null" +if command -v yazi; then + yazi_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/yazi/keymap.toml" + yazi_shortcuts_tmp="$yazi_shortcuts.tmp" +else + yazi_shortcuts="/dev/null" + yazi_shortcuts_tmp="/dev/null" +fi command -v ranger && ranger_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/ranger/shortcuts.conf" || ranger_shortcuts="/dev/null" -command -v qutebrowser && qute_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/qutebrowser/shortcuts.py" || qute_shortcuts="/dev/null" +command -v qutebrowser && qute_shortcuts="$HOME/.qutebrowser/shortcuts.py" || qute_shortcuts="/dev/null" command -v fish && fish_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/fish/shortcuts.fish" || fish_shortcuts="/dev/null" command -v vifm && vifm_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/vifm/shortcuts.rc" || vifm_shortcuts="/dev/null" @@ -22,7 +28,7 @@ printf "# vim: filetype=sh\\n" >"$fish_shortcuts" printf "# vim: filetype=sh\\nalias " >"$shell_shortcuts" printf "# vim: filetype=sh\\n" >"$shell_env_shortcuts" printf "\" vim: filetype=vim\\n" >"$vifm_shortcuts" -cp "$HOME/.config/yazi/keymap-default.toml" "$yazi_shortcuts" +[ -f "$HOME/.config/yazi/keymap-default.toml" ] && cp "$HOME/.config/yazi/keymap-default.toml" "$yazi_shortcuts" # Format the `directories` file in the correct syntax and sent it to all three configs. eval "echo \"$(cat "$bmdirs")\"" | @@ -43,7 +49,7 @@ eval "echo \"$(cat "$bmdirs")\"" | printf(\"vim.keymap.set('n', '<localleader><localleader>%s', function() require('mini.files').open('%s') end, { noremap = true, silent = true, desc = '%s' })\n\", \$1, \$2, desc_path) >> \"$nvim_shortcuts\" ; desc_path = \$2; gsub(\"^/home/$USER/\",\"~/\",desc_path); key_array = \"\"; for(i=1; i<=length(\$1); i++) { if(i==1) key_array = \"\\\"\" substr(\$1,i,1) \"\\\"\"; else key_array = key_array \", \\\"\" substr(\$1,i,1) \"\\\"\" } - printf(\"\\t{ on = [ %s ], run = \\\"cd %s\\\", desc = \\\"Go to %s\\\" },\\n\",key_array,\$2,desc_path) >> \"$yazi_shortcuts.tmp\"}" + printf(\"\\t{ on = [ %s ], run = \\\"cd %s\\\", desc = \\\"Go to %s\\\" },\\n\",key_array,\$2,desc_path) >> \"$yazi_shortcuts_tmp\"}" # Format the `files` file in the correct syntax and sent it to both configs. eval "echo \"$(cat "$bmfiles")\"" | @@ -66,10 +72,10 @@ eval "echo \"$(cat "$bmfiles")\"" | printf(\"vim.keymap.set('n', '<localleader><localleader>%s', '<cmd>e %s<cr>', { noremap = true, silent = true, desc = '%s' })\n\", \$1, \$2, desc_path) >> \"$nvim_shortcuts\" ; desc_path = \$2; gsub(\"^/home/$USER/\",\"~/\",desc_path); key_array = \"\"; for(i=1; i<=length(\$1); i++) { if(i==1) key_array = \"\\\"\" substr(\$1,i,1) \"\\\"\"; else key_array = key_array \", \\\"\" substr(\$1,i,1) \"\\\"\" } - printf(\"\\t{ on = [ %s ], run = [ 'reveal %s', 'open' ], desc = \\\"Open %s\\\" },\\n\", key_array, \$2, desc_path) >> \"$yazi_shortcuts.tmp\" }" + printf(\"\\t{ on = [ %s ], run = [ 'reveal %s', 'open' ], desc = \\\"Open %s\\\" },\\n\", key_array, \$2, desc_path) >> \"$yazi_shortcuts_tmp\" }" # Merge bookmarks into keymap-default.toml -if [ -f "$yazi_shortcuts.tmp" ]; then +if [ -f "$yazi_shortcuts_tmp" ]; then # Find the line with the closing bracket in the [mgr] section line_num=$(grep -n "^]" "$yazi_shortcuts" | head -1 | cut -d: -f1) @@ -77,11 +83,11 @@ if [ -f "$yazi_shortcuts.tmp" ]; then head -n $((line_num - 1)) "$yazi_shortcuts" >"$yazi_shortcuts.new" echo "" >>"$yazi_shortcuts.new" echo " # Custom bookmarks" >>"$yazi_shortcuts.new" - cat "$yazi_shortcuts.tmp" >>"$yazi_shortcuts.new" + cat "$yazi_shortcuts_tmp" >>"$yazi_shortcuts.new" echo "]" >>"$yazi_shortcuts.new" tail -n +$((line_num + 1)) "$yazi_shortcuts" >>"$yazi_shortcuts.new" # Replace the original file mv "$yazi_shortcuts.new" "$yazi_shortcuts" - rm -f "$yazi_shortcuts.tmp" + rm -f "$yazi_shortcuts_tmp" fi diff --git a/fedora/.local/bin/bookmarks b/fedora/.local/bin/bookmarks deleted file mode 100755 index a892a33..0000000 --- a/fedora/.local/bin/bookmarks +++ /dev/null @@ -1,211 +0,0 @@ -#!/bin/sh - -usage() { - echo "Open bookmarks, URLs, or browser history in a program." - echo "" - echo "Usage: ${0##*/} [OPTIONS]" - echo "" - echo "Options:" - echo " -h : Show this message" - echo " -b : Open a browser bookmark" - echo " -c : Copy a URL from snippets/urls to the clipboard" - echo " -o : Get a URL from snippets/urls and open it in a new browser window" - echo " -p : Get a URL from snippets/urls and open it in a private browser window" - echo " -s : Open browser history" - echo " -t : Get a URL from snippets/urls and type it using xdotool" - echo " -v : Open a browser bookmark in private browser window" - echo "" - echo "Programs:" - echo " browser : System default browser" - echo " lynx : A text browser for World Wide Web" - echo " w3m : A text WWW browser, similar to lynx" - echo "" - echo "Examples:" - echo " ${0##*/} -b # Opens a browser bookmark in a program" - echo " ${0##*/} -c # Copies a URL from snippets/urls to the clipboard" - echo " ${0##*/} -o # Opens a URL from snippets/urls in a new browser window" - echo " ${0##*/} -p # Opens a URL in a private browser window" - echo " ${0##*/} -s # Opens browser history in a program" - echo " ${0##*/} -v # Opens browser boomark in private browser window" -} - -addurls() { - url=$(echo | dmenu -i -p "Enter a url: ") - [ -z "$url" ] && printf "Error: url must be provided\n\n" && exit 0 - - description=$(echo | dmenu -i -p "Enter a description of the url: ") - [ -z "$description" ] && echo "https://$url" >>~/.local/share/thesiah/snippets - [ -n "$description" ] && echo "$description https://$url" >>~/.local/share/thesiah/snippets -} - -opentool() { - available_tools="" - command -v xdg-open 2>/dev/null | grep -v "alias" -q && available_tools="$available_tools xdg-open" - command -v open 2>/dev/null | grep -v "alias" -q && available_tools="$available_tools open" - command -v lynx 2>/dev/null | grep -v "alias" -q && available_tools="$available_tools lynx" - command -v w3m 2>/dev/null | grep -v "alias" -q && available_tools="$available_tools w3m" - available_tools=$(printf "%s" "$available_tools" | awk '{$1=$1; print}' | tr ' ' '\n') - if [ -z "$available_tools" ]; then - printf "No browser found\n" >&2 - exit 1 - fi - - opentool=$(printf "%s\n" "$available_tools" | dmenu -i -p "Choose an open tool:") - - # Set the selected tool to the variable 'open' - case "$opentool" in - xdg-open) xdg-open "$1" ;; - open) - case "$(uname -s)" in - Darwin) open "$1" ;; - *) xdg-open "$1" ;; - esac - ;; - lynx) setsid -f "$TERMINAL" -e lynx "$1" ;; - w3m) setsid -f "$TERMINAL" -e w3m "$1" ;; - *) echo "Invalid selection" >&2 && exit 1 ;; - esac -} - -openwindow() { - if [ "$1" = "private" ]; then - case "$BROWSER" in - *qutebrowser*) "$BROWSER" --target private-window "$url" ;; - *firefox* | *librewolf*) "$BROWSER" --private-window "$url" ;; - esac - else - case "$BROWSER" in - *qutebrowser*) "$BROWSER" --target window "$url" ;; - *firefox* | *librewolf*) "$BROWSER" --new-window "$url" ;; - esac - fi -} - -openinbrowser() { - # Extract only the default part of the profile name - case $BROWSER in - *firefox*) - profiles_ini_path="$HOME/.mozilla/firefox/profiles.ini" - profile=$(awk '/\[Install/ {found=1} found && /^Default=/ {split($0, arr, "."); print arr[2]; exit}' "$profiles_ini_path") - profile_dir=$(find ~/.mozilla/firefox -type d -name "*.$profile*" | head -n 1) - db_path="$profile_dir/places.sqlite" - ;; - *librewolf*) - profiles_ini_path="$HOME/.librewolf/profiles.ini" - profile=$(awk '/\[Install/ {found=1} found && /^Default=/ {split($0, arr, "."); print arr[2]; exit}' "$profiles_ini_path") - profile_dir=$(find ~/.librewolf -type d -name "*.$profile*" | head -n 1) - db_path="$profile_dir/places.sqlite" - ;; - *qutebrowser*) - profile_dir="${XDG_DATA_HOME:-${HOME}/.local/share}/qutebrowser" - db_path="$profile_dir/history.sqlite" - ;; - *) echo "Default browser path is needed." && exit ;; - esac - - tmp_file="$(mktemp)" - cp -f "$db_path" "$tmp_file" - - type dmenu >/dev/null 2>&1 && - selection="dmenu -i -l 20 -p \"Choose a $1 to open:\"" || - selection="fzf-tmux --reverse --cycle --ansi --delimiter='|' --with-nth=1..-2" - - cols=$((${COLUMNS:-90} / 3)) - case "$1" in - *bookmark*) - case "$BROWSER" in - qutebrowser) bookmarks -o ;; - *firefox* | *librewolf*) - sqlite_query=" - SELECT substr(b.title, 1, $cols) || ' | ' || p.url AS bookmark - FROM moz_bookmarks b - JOIN moz_places p ON b.fk = p.id - WHERE b.type = 1 AND p.url LIKE 'http%' AND b.title NOT NULL - ORDER BY b.title; - " - ;; - *qutebrowser*) geturls && openwindow && exit ;; - esac - ;; - *history*) - case "$BROWSER" in - *qutebrowser*) - sqlite_query=" - SELECT substr(h.title, 1, $cols) || ' | ' || h.url AS bookmark - FROM CompletionHistory h - ORDER BY h.last_atime DESC - LIMIT 100; - " - ;; - *firefox* | *librewolf*) - sqlite_query=" - SELECT substr(p.title, 1, $cols) || ' | ' || p.url - FROM moz_places p - JOIN moz_historyvisits hv ON hv.place_id = p.id - ORDER BY hv.visit_date DESC - LIMIT 100; - " - ;; - esac - ;; - esac - choice=$(sqlite3 "$tmp_file" "$sqlite_query" | eval "$selection" | cut -d'|' -f2 | sed 's|.*\(https://\)|\1|' | xargs) - if [ -n "$choice" ]; then - if echo "$1" | grep -q "private"; then - "$BROWSER" --private-window "$choice" - else - opentool "$choice" - fi - else - exit - fi - rm "$tmp_file" -} - -geturls() { - urls=$(cat ~/.config/qutebrowser/quickmarks ~/.config/qutebrowser/bookmarks/urls ~/.local/share/thesiah/snippets ~/.local/share/thesiah/urls 2>/dev/null) - choice=$(echo "$urls" | grep -v -e '^#' -e '^$' | awk ' - { - if ($1 ~ /^https?:\/\//) { alias = substr($0, index($0, $2)) } # Case 2: URL first - else { alias = substr($0, 1, length($0) - length($NF) - 1) } # Case 1: URL last - print alias - }' | dmenu -i -l 50 -p "Choose an alias $1:") - - [ -z "$choice" ] && exit - url=$(echo "$urls" | grep -v -e '^#' -e '^$' | awk -v choice="$choice" ' - { - if ($1 ~ /^https?:\/\//) { url = $1; alias = substr($0, index($0, $2)) } # Case 2 - else { alias = substr($0, 1, length($0) - length($NF) - 1); url = $NF } # Case 1 - if (alias == choice) print url - }') -} - -copytoclipboard() { - if command -v xclip >/dev/null 2>&1; then - printf "%s" "$url" | xclip -selection clipboard - elif command -v clipcopy >/dev/null 2>&1; then - printf "%s" "$url" | clipcopy - elif command -v xsel >/dev/null 2>&1; then - printf "%s" "$url" | xsel --clipboard --input - else - echo "Clipboard utility not found. Install xclip, clipcopy, or xsel." >&2 - exit 1 - fi - notify-send "'$choice' copied in clipbaord" "$url" -} - -[ $# -eq 0 ] && usage && exit 1 - -while getopts "abchopstv" opt; do - case $opt in - a) addurls ;; - b) openinbrowser "bookmark" ;; - c) geturls "to copy" && copytoclipboard ;; - o) geturls "to open in $BROWSER" && openwindow ;; - p) geturls "to open in private $BROWSER" && openwindow private ;; - s) openinbrowser "history" ;; - t) geturls "to type under cursor" && xdotool type "$url" ;; - v) openinbrowser "private bookmark" ;; - h | *) usage && exit 0 ;; - esac -done diff --git a/fedora/.local/bin/chafa b/fedora/.local/bin/chafa Binary files differnew file mode 100755 index 0000000..89b4c96 --- /dev/null +++ b/fedora/.local/bin/chafa diff --git a/fedora/.local/bin/eza b/fedora/.local/bin/eza Binary files differnew file mode 100755 index 0000000..0d40b22 --- /dev/null +++ b/fedora/.local/bin/eza diff --git a/fedora/.local/bin/fzf b/fedora/.local/bin/fzf Binary files differnew file mode 100755 index 0000000..0e89dac --- /dev/null +++ b/fedora/.local/bin/fzf diff --git a/fedora/.local/bin/fzf-preview.sh b/fedora/.local/bin/fzf-preview.sh new file mode 100755 index 0000000..5f99697 --- /dev/null +++ b/fedora/.local/bin/fzf-preview.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# +# The purpose of this script is to demonstrate how to preview a file or an +# image in the preview window of fzf. +# +# Dependencies: +# - https://github.com/sharkdp/bat +# - https://github.com/hpjansson/chafa +# - https://iterm2.com/utilities/imgcat + +if [[ $# -ne 1 ]]; then + >&2 echo "usage: $0 FILENAME[:LINENO][:IGNORED]" + exit 1 +fi + +file=${1/#\~\//$HOME/} + +center=0 +if [[ ! -r $file ]]; then + if [[ $file =~ ^(.+):([0-9]+)\ *$ ]] && [[ -r ${BASH_REMATCH[1]} ]]; then + file=${BASH_REMATCH[1]} + center=${BASH_REMATCH[2]} + elif [[ $file =~ ^(.+):([0-9]+):[0-9]+\ *$ ]] && [[ -r ${BASH_REMATCH[1]} ]]; then + file=${BASH_REMATCH[1]} + center=${BASH_REMATCH[2]} + fi +fi + +type=$(file --brief --dereference --mime -- "$file") + +if [[ ! $type =~ image/ ]]; then + if [[ $type =~ =binary ]]; then + file "$1" + exit + fi + + # Sometimes bat is installed as batcat. + if command -v batcat > /dev/null; then + batname="batcat" + elif command -v bat > /dev/null; then + batname="bat" + else + cat "$1" + exit + fi + + ${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never --highlight-line="${center:-0}" -- "$file" + exit +fi + +dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES} +if [[ $dim == x ]]; then + dim=$(stty size < /dev/tty | awk '{print $2 "x" $1}') +elif ! [[ $KITTY_WINDOW_ID ]] && ((FZF_PREVIEW_TOP + FZF_PREVIEW_LINES == $(stty size < /dev/tty | awk '{print $1}'))); then + # Avoid scrolling issue when the Sixel image touches the bottom of the screen + # * https://github.com/junegunn/fzf/issues/2544 + dim=${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES - 1)) +fi + +# 1. Use icat (from Kitty) if kitten is installed +if [[ $KITTY_WINDOW_ID ]] || [[ $GHOSTTY_RESOURCES_DIR ]] && command -v kitten > /dev/null; then + # 1. 'memory' is the fastest option but if you want the image to be scrollable, + # you have to use 'stream'. + # + # 2. The last line of the output is the ANSI reset code without newline. + # This confuses fzf and makes it render scroll offset indicator. + # So we remove the last line and append the reset code to its previous line. + kitten icat --clear --transfer-mode=memory --unicode-placeholder --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/' + +# 2. Use chafa with Sixel output +elif command -v chafa > /dev/null; then + chafa -s "$dim" "$file" + # Add a new line character so that fzf can display multiple images in the preview window + echo + +# 3. If chafa is not found but imgcat is available, use it on iTerm2 +elif command -v imgcat > /dev/null; then + # NOTE: We should use https://iterm2.com/utilities/it2check to check if the + # user is running iTerm2. But for the sake of simplicity, we just assume + # that's the case here. + imgcat -W "${dim%%x*}" -H "${dim##*x}" "$file" + +# 4. Cannot find any suitable method to preview the image +else + file "$file" +fi diff --git a/fedora/.local/bin/fzf-tmux b/fedora/.local/bin/fzf-tmux new file mode 100755 index 0000000..e73a908 --- /dev/null +++ b/fedora/.local/bin/fzf-tmux @@ -0,0 +1,257 @@ +#!/usr/bin/env bash +# fzf-tmux: starts fzf in a tmux pane +# usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS] + +fail() { + >&2 echo "$1" + exit 2 +} + +fzf="$(command which fzf)" || fzf="$(dirname "$0")/fzf" +[[ -x $fzf ]] || fail 'fzf executable not found' + +args=() +opt="" +skip="" +swap="" +close="" +term="" +[[ -n $LINES ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}") +[[ -n $COLUMNS ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}") + +tmux_version=$(tmux -V | sed 's/[^0-9.]//g') +tmux_32=$(awk '{print ($1 >= 3.2)}' <<< "$tmux_version" 2> /dev/null || bc -l <<< "$tmux_version >= 3.2") + +help() { + >&2 echo 'usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS] + + LAYOUT OPTIONS: + (default layout: -d 50%) + + Popup window (requires tmux 3.2 or above): + -p [WIDTH[%][,HEIGHT[%]]] (default: 50%) + -w WIDTH[%] + -h HEIGHT[%] + -x COL + -y ROW + + Split pane: + -u [HEIGHT[%]] Split above (up) + -d [HEIGHT[%]] Split below (down) + -l [WIDTH[%]] Split left + -r [WIDTH[%]] Split right +' + exit +} + +while [[ $# -gt 0 ]]; do + arg="$1" + shift + [[ -z $skip ]] && case "$arg" in + -) + term=1 + ;; + --help) + help + ;; + --version) + echo "fzf-tmux (with fzf $("$fzf" --version))" + exit + ;; + -p* | -w* | -h* | -x* | -y* | -d* | -u* | -r* | -l*) + if [[ $arg =~ ^-[pwhxy] ]]; then + [[ $opt =~ "-E" ]] || opt="-E" + elif [[ $arg =~ ^.[lr] ]]; then + opt="-h" + if [[ $arg =~ ^.l ]]; then + opt="$opt -d" + swap="; swap-pane -D ; select-pane -L" + close="; tmux swap-pane -D" + fi + else + opt="" + if [[ $arg =~ ^.u ]]; then + opt="$opt -d" + swap="; swap-pane -D ; select-pane -U" + close="; tmux swap-pane -D" + fi + fi + if [[ ${#arg} -gt 2 ]]; then + size="${arg:2}" + else + if [[ $1 =~ ^[0-9%,]+$ ]] || [[ $1 =~ ^[A-Z]$ ]]; then + size="$1" + shift + else + continue + fi + fi + + if [[ $arg =~ ^-p ]]; then + if [[ -n $size ]]; then + w=${size%%,*} + h=${size##*,} + opt="$opt -w$w -h$h" + fi + elif [[ $arg =~ ^-[whxy] ]]; then + opt="$opt ${arg:0:2}$size" + elif [[ $size =~ %$ ]]; then + size=${size:0:${#size}-1} + if [[ $tmux_32 == 1 ]]; then + if [[ -n $swap ]]; then + opt="$opt -l $((100 - size))%" + else + opt="$opt -l $size%" + fi + else + if [[ -n $swap ]]; then + opt="$opt -p $((100 - size))" + else + opt="$opt -p $size" + fi + fi + else + if [[ -n $swap ]]; then + if [[ $arg =~ ^.l ]]; then + max=$columns + else + max=$lines + fi + size=$((max - size)) + [[ $size -lt 0 ]] && size=0 + opt="$opt -l $size" + else + opt="$opt -l $size" + fi + fi + ;; + --) + # "--" can be used to separate fzf-tmux options from fzf options to + # avoid conflicts + skip=1 + continue + ;; + *) + args+=("$arg") + ;; + esac + [[ -n $skip ]] && args+=("$arg") +done + +if [[ -z $TMUX ]]; then + "$fzf" "${args[@]}" + exit $? +fi + +# * --height option is not allowed +# * CTRL-Z is also disabled +# * fzf-tmux script is not compatible with --tmux option in fzf 0.53.0 or later +args=("${args[@]}" "--no-height" "--bind=ctrl-z:ignore" "--no-tmux") + +# Handle zoomed tmux pane without popup options by moving it to a temp window +if [[ ! $opt =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then + zoomed_without_popup=1 + original_window=$(tmux display-message -p "#{window_id}") + tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'") + tmux swap-pane -t $tmp_window \; select-window -t $tmp_window +fi + +set -e + +# Clean up named pipes on exit +id=$RANDOM +argsf="${TMPDIR:-/tmp}/fzf-args-$id" +fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id" +fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id" +fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id" +if tmux_win_opts=$(tmux show-options -p remain-on-exit \; show-options -p synchronize-panes 2> /dev/null); then + tmux_win_opts=($(sed '/ off/d; s/synchronize-panes/set-option -p synchronize-panes/; s/remain-on-exit/set-option -p remain-on-exit/; s/$/ \\;/' <<< "$tmux_win_opts")) + tmux_off_opts='; set-option -p synchronize-panes off ; set-option -p remain-on-exit off' +else + tmux_win_opts=($(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/')) + tmux_off_opts='; set-window-option synchronize-panes off ; set-window-option remain-on-exit off' +fi +cleanup() { + \rm -f $argsf $fifo1 $fifo2 $fifo3 + + # Restore tmux window options + if [[ ${#tmux_win_opts[@]} -gt 1 ]]; then + eval "tmux ${tmux_win_opts[*]}" + fi + + # Remove temp window if we were zoomed without popup options + if [[ -n $zoomed_without_popup ]]; then + tmux display-message -p "#{window_id}" > /dev/null + tmux swap-pane -t $original_window \; \ + select-window -t $original_window \; \ + kill-window -t $tmp_window \; \ + resize-pane -Z + fi + + if [[ $# -gt 0 ]]; then + trap - EXIT + exit 130 + fi +} +trap 'cleanup 1' SIGUSR1 +trap 'cleanup' EXIT + +envs="export TERM=$TERM " +if [[ $opt =~ "-E" ]]; then + if [[ $tmux_version == 3.2 ]]; then + FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS" + elif [[ $tmux_32 == 1 ]]; then + FZF_DEFAULT_OPTS="--border $FZF_DEFAULT_OPTS" + opt="-B $opt" + else + echo "fzf-tmux: tmux 3.2 or above is required for popup mode" >&2 + exit 2 + fi +fi +envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")" +envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")" +envs="$envs FZF_DEFAULT_OPTS_FILE=$(printf %q "$FZF_DEFAULT_OPTS_FILE")" +[[ -n $RUNEWIDTH_EASTASIAN ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")" +[[ -n $BAT_THEME ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")" +echo "$envs;" > "$argsf" + +# Build arguments to fzf +opts=$(printf "%q " "${args[@]}") + +pppid=$$ +echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" >> $argsf +close="; trap - EXIT SIGINT SIGTERM $close" + +export TMUX=$(cut -d , -f 1,2 <<< "$TMUX") +mkfifo -m o+w $fifo2 +if [[ $opt =~ "-E" ]]; then + cat $fifo2 & + if [[ -n $term ]] || [[ -t 0 ]]; then + cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf + else + mkfifo $fifo1 + cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; out=\$? $close; exit \$out" >> $argsf + cat <&0 > $fifo1 & + fi + + tmux popup -d "$PWD" $opt "bash $argsf" > /dev/null 2>&1 + exit $? +fi + +mkfifo -m o+w $fifo3 +if [[ -n $term ]] || [[ -t 0 ]]; then + cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf +else + mkfifo $fifo1 + cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf + cat <&0 > $fifo1 & +fi +tmux \ + split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \ + $tmux_off_opts \ + > /dev/null 2>&1 || { + "$fzf" "${args[@]}" + exit $? +} +cat $fifo2 +exit "$(cat $fifo3)" diff --git a/fedora/.local/bin/fzffiles b/fedora/.local/bin/fzffiles new file mode 100755 index 0000000..97047e9 --- /dev/null +++ b/fedora/.local/bin/fzffiles @@ -0,0 +1,99 @@ +#!/bin/sh + +# The set -e option instructs sh to immediately exit if any command has a non-zero exit status +set -e + +# Set new line and tab for word splitting +IFS=' +' + +# Get the list of selected files with key bindings for specific paths +files=$(fzf-tmux \ + --header "^a pwd ^b public ^d .dotfiles ^f configs ^g git ^h home ^k desktop ^r scripts ^s suckless ^u staged files ^v private ^/ help" \ + --preview "selection={}; + clean=\$(printf '%s' \"\$selection\" | sed -e 's/^📄 //' -e 's/^✏️ //' -e 's/^✅ //' -e 's/^❌ //' -e 's/^🔀 //' -e 's/^❓ //'); + [ -z \"\$clean\" ] && { echo 'No selection'; exit 0; } + target=\$(readlink -f \"\$clean\" 2>/dev/null || printf '%s' \"\$clean\"); + if [ -z \"\$target\" ]; then + echo 'Could not resolve path'; + exit 0; + fi + if [ -f \"\$target\" ]; then + dir=\$(dirname \"\$target\"); + if git_root=\$(git -C \"\$dir\" rev-parse --show-toplevel 2>/dev/null); then + rel=\${target#\"\$git_root\"/}; + diff_output=\$(git -C \"\$git_root\" diff --color -- \"\$rel\"); + if [ -n \"\$diff_output\" ]; then + printf '%s\n' \"\$diff_output\" + exit 0 + fi + diff_output=\$(git -C \"\$git_root\" diff --color --cached -- \"\$rel\"); + if [ -n \"\$diff_output\" ]; then + printf '%s\n' \"\$diff_output\" + exit 0 + fi + fi + fi + if [ -d \"\$target\" ]; then + exa --color=always --long --all --header --icons --git \"\$target\" + elif [ -f \"\$target\" ]; then + bat --color=always --style=header,grid --line-range=:500 \"\$target\" + else + file -h \"\$target\" + fi" \ + --reverse \ + --query="$1" \ + --multi \ + --exit-0 \ + --prompt " 💡 " \ + --bind "ctrl-a:change-prompt( ⚡ )+reload(fd -H -L -t f -E .Trash -E .git -E .cache . $PWD)" \ + --bind "ctrl-b:change-prompt( 🌎 )+reload(fd -H -L -t f -E .Trash -E .git -E .cache . ${XDG_PUBLICSHARE_DIR:-${HOME}/Public})" \ + --bind "ctrl-d:change-prompt( ⚙️ )+reload(fd -H -L -t f -E .Trash -E .git -E .cache . ${XDG_DOTFILES_DIR:-${HOME}/.dotfiles})" \ + --bind "ctrl-f:change-prompt( 🗂️ )+reload(fd -H -L -t f -E .Trash -E .git -E .cache . ${XDG_CONFIG_HOME:-${HOME}/.config})" \ + --bind "ctrl-g:change-prompt( )+reload(fd -H -L -t f -E .Trash -E .git -E .cache . $HOME/Private/repos $HOME/Public/repos)" \ + --bind "ctrl-h:change-prompt( 🏠 )+reload(fd -H -L -t f -E .Trash -E .git -E .cache . $HOME)" \ + --bind "ctrl-k:change-prompt( 🖥️ )+reload(fd -H -L -t f -E .Trash -E .git -E .cache . ${XDG_DESKTOP_DIR:-${HOME}/Desktop})" \ + --bind "ctrl-r:change-prompt( 👟 )+reload(fd -H -L -t f -E .Trash -E .git -E .cache -E zsh . ${XDG_SCRIPTS_HOME:-${HOME}/.local/bin})" \ + --bind "ctrl-s:change-prompt( 🛠 )+reload(find ${XDG_SOURCES_HOME:-${HOME}/.local/src}/suckless -maxdepth 2 -type f -not -path '*/.git/*')" \ + --bind "ctrl-u:change-prompt( 📝 )+reload(if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then top=\$(git rev-parse --show-toplevel 2>/dev/null); git -C \"\$top\" status --porcelain | awk -v root=\"\$top\" '{ + staged=substr(\$0,1,1); + unstaged=substr(\$0,2,1); + file=substr(\$0,4); + gsub(/^ +/, \"\", file); + if (file == \"\") next; + if (staged == \"?\" && unstaged == \"?\") icon=\"📄\"; + else if (staged == \"!\" && unstaged == \"!\") icon=\"❌\"; + else if (staged != \" \" && staged != \"?\" && unstaged != \" \" && unstaged != \"?\") icon=\"🔀\"; + else if (staged != \" \" && staged != \"?\") icon=\"✅\"; + else if (unstaged != \" \") icon=\"✏️\"; + else icon=\"❓\"; + print icon \" \" root \"/\" file + }'; else echo 'This is not a git repository.'; fi)" \ + --bind "ctrl-v:change-prompt( 🔒 )+reload(fd -H -L -t f -E .Trash -E .git -E .cache . $HOME/Private)" \ + --bind 'ctrl-/:change-prompt( ❓ )+reload(echo "^a all +^b public +^c configs +^d .dotfiles +^g git +^k desktop +^r scripts +^s suckless +^u staged files +^v private +^/ help")') + +# Check if any files were selected, and exit if not +[ -z "$files" ] && exit 0 + +files=$(printf '%s\n' "$files" | sed -e 's/^📄 //' -e 's/^✏️ //' -e 's/^✅ //' -e 's/^❌ //' -e 's/^🔀 //' -e 's/^❓ //') + +if [ -d "$files" ]; then + absolute_files=$(realpath $files) + if echo "$absolute_files" | while read -r file; do file --mime-type "$file" | grep -q 'video/'; done; then + mpv --quiet --loop $absolute_files + else + openfiles "$absolute_files" + fi +else + openfiles "$files" +fi diff --git a/fedora/.local/bin/fzffns b/fedora/.local/bin/fzffns new file mode 100755 index 0000000..c919723 --- /dev/null +++ b/fedora/.local/bin/fzffns @@ -0,0 +1,74 @@ +#!/bin/sh + +# Print all functions and comments in a readable format +# Set the filename of the script containing the functions +file="${ZDOTDIR:-${XDG_CONFIG_HOME:-${HOME}/.config}/zsh}/scripts.zsh" + +# Initialize an empty variable to hold functions, aliases, and comments +functions="" + +# Parse the file for function names, aliases, and comments +while IFS= read -r line || [ -n "$line" ]; do + case "$line" in + \#*) + if [ "$(printf '%s' "$line" | cut -c 2)" != "#" ] && [ "$(printf '%s' "$line" | cut -c 2)" != "!" ]; then + # Remove the '#' from the comment line + comment=$(printf '%s' "$line" | sed 's/^# //') + + # Read the next line to check for alias or function definition + IFS= read -r next_line || break + + # Check if it's an alias definition + if echo "$next_line" | grep -q '^alias '; then + alias_name=$(echo "$next_line" | sed -n 's/^alias \([a-zA-Z0-9_]*\)=.*$/\1/p') + + # Read another line to get the function definition + IFS= read -r func_line || break + f_name=$(printf '%s' "$func_line" | sed -n 's/^function \([^(]*\)().*$/\1/p') + + if [ -n "$f_name" ]; then + functions="$functions$f_name|$alias_name|$comment\n" + fi + + # Check if it's a function definition + elif echo "$next_line" | grep -q '^function '; then + f_name=$(printf '%s' "$next_line" | sed -n 's/^function \([^(]*\)().*$/\1/p') + if [ -n "$f_name" ]; then + functions="$functions$f_name||$comment\n" + fi + fi + fi + ;; + esac +done <"$file" + +# Sort the functions alphabetically by name +sorted=$(printf '%b' "$functions" | sort) + +# Print out the sorted functions with aliases and comments in a readable format +formatted=$(printf '%b' "$sorted" | while IFS='|' read -r f_name alias_name comment; do + if [ -n "$alias_name" ]; then + printf 'fn: %-30s - %s (alias: %s)\n' "$f_name" "$comment" "$alias_name" + else + printf 'fn: %-30s - %s\n' "$f_name" "$comment" + fi +done) + +# Use fzf to select a function +selected=$(printf '%b' "$formatted" | fzf-tmux --header "Select a function:" --reverse) + +# Check if a function was selected +if [ -n "$selected" ]; then + # Extract the function name + f_name=$(echo "$selected" | cut -d ' ' -f 2 | sed 's/[[:space:]]\+//g') + + # Get the line number of the function definition + line_number=$(grep -n "^function $f_name(" "$file" | cut -d ':' -f 1) + + # Open the function in nvim at the specific line number + if [ -n "$line_number" ]; then + nvim "+$line_number" "$file" + else + echo "Function '$f_name' not found in $file." + fi +fi diff --git a/fedora/.local/bin/fzfpass b/fedora/.local/bin/fzfpass new file mode 100755 index 0000000..5190f8e --- /dev/null +++ b/fedora/.local/bin/fzfpass @@ -0,0 +1,88 @@ +#!/bin/sh + +set -e + +usage() { + echo "Find pass gpg files in Password-Store using fzf." + echo "" + echo "Usage: ${0##*/} [-h|--help]" + echo "" + echo "Options:" + echo " -h, --help : Show this message" + echo "" + echo "Shortcuts:" + echo " return - echo password and copy to clipboard (wayland only)" + echo " ctrl+a - new password (named as per the prompt)" + echo " ctrl+e - edit selected password" + echo " ctrl+g - regenerate selected password" + echo " ctrl+r - rename selected password" + echo " ctrl+x - delete selected password" + echo " tab - tab complete" + echo " esc/ctrl+c - exit" + exit 0 +} + +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + usage +fi + +passdir=${PASSWORD_STORE_DIR:-$HOME/.local/share/.password-store} +cd "$passdir" + +# Unlock the password for this session +pass show "$(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g' | sed 's/^..//' | head -n 1)" >/dev/null + +# Main fzf session +passfile=$( + tree -Ffi | grep '.gpg' | sed 's/.gpg$//g' | sed 's/^..//' | + fzf-tmux \ + --header="🔑 Password Manager" \ + --reverse \ + --no-mouse \ + --preview="pass {}" \ + --header="🔑 ^a: Generate | ^e: Edit | ^g: Generate (no symbol) | ^r: Rename | ^s: Generate (symbol) | ^x: Delete | tab: Replace" \ + --bind="ctrl-a:execute(if [ -z {q} ]; then read -p \"Can't generate empty password. Press enter to continue...\"; else pass generate -n {q} < /dev/tty > /dev/tty 2>&1 && pass edit {q} < /dev/tty > /dev/tty 2>&1; fi)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \ + --bind="ctrl-e:execute(pass edit {} < /dev/tty > /dev/tty 2>&1)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \ + --bind="ctrl-r:execute(bash -c ' +echo -n \"Enter new name for {}: \" > /dev/tty; +read new_name < /dev/tty; +if [ -n \"\$new_name\" ]; then + pass mv {} \"\$new_name\" || echo \"Rename failed.\" > /dev/tty; +else + echo \"No name entered. Rename aborted.\" > /dev/tty; +fi' < /dev/tty > /dev/tty 2>&1)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \ + --bind="ctrl-g:execute(if [ -z {} ]; then read -p \"Can't generate empty password. Press enter to continue...\"; else pass generate -in {} < /dev/tty > /dev/tty 2>&1 && pass edit {} < /dev/tty > /dev/tty 2>&1; fi)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \ + --bind="ctrl-s:execute(if [ -z {} ]; then read -p \"Can't generate empty password. Press enter to continue...\"; else pass generate -i {} < /dev/tty > /dev/tty 2>&1 && pass edit {} < /dev/tty > /dev/tty 2>&1; fi)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \ + --bind="ctrl-x:execute(pass rm {} < /dev/tty > /dev/tty 2>&1)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \ + --bind="tab:replace-query" +) + +show_passdata=false + +if [ "$1" = "-i" ]; then + show_passdata=true + shift +fi + +if [ "$show_passdata" = true ]; then + passdata="$(pass "$passfile")" + echo "$passdata" +else + password="$(pass show "$passfile" | head -n 1)" + echo "$password" + + if [ -n "$password" ]; then + case "$(uname)" in + Darwin*) + printf "%s" "$password" | pbcopy # Use pbcopy on macOS + ;; + Linux*) + printf "%s" "$password" | xclip -selection clipboard # Use xclip on Linux + ;; + *) + echo "Unsupported operating system" + ;; + esac + sleep 0.1 + fi +fi diff --git a/fedora/.local/bin/imgcat b/fedora/.local/bin/imgcat new file mode 100755 index 0000000..af50702 --- /dev/null +++ b/fedora/.local/bin/imgcat @@ -0,0 +1,274 @@ +#!/usr/bin/env bash + +set -o pipefail + +# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux; +# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It +# only accepts ESC backslash for ST. We use TERM instead of TMUX because TERM +# gets passed through ssh. +function print_osc() { + if [[ $TERM == screen* || $TERM == tmux* ]]; then + printf "\033Ptmux;\033\033]" + else + printf "\033]" + fi +} + +# More of the tmux workaround described above. +function print_st() { + if [[ $TERM == screen* || $TERM == tmux* ]]; then + printf "\a\033\\" + else + printf "\a" + fi +} + +function load_version() { + if [ -z ${IMGCAT_BASE64_VERSION+x} ]; then + IMGCAT_BASE64_VERSION=$(base64 --version 2>&1) + export IMGCAT_BASE64_VERSION + fi +} + +function b64_encode() { + load_version + if [[ $IMGCAT_BASE64_VERSION =~ GNU ]]; then + # Disable line wrap + base64 -w0 + else + base64 + fi +} + +function b64_decode() { + load_version + if [[ $IMGCAT_BASE64_VERSION =~ fourmilab ]]; then + BASE64ARG=-d + elif [[ $IMGCAT_BASE64_VERSION =~ GNU ]]; then + BASE64ARG=-di + else + BASE64ARG=-D + fi + base64 $BASE64ARG +} + +# print_image filename inline base64contents print_filename width height preserve_aspect_ratio +# filename: Filename to convey to client +# inline: 0 or 1, if set to 1, the file will be displayed inline, otherwise, it will be downloaded +# base64contents: Base64-encoded contents +# print_filename: 0 or 1, if set to 1, print the filename after outputting the image +# width: set output width of the image in character cells, pixels or percent +# height: set output height of the image in character cells, pixels or percent +# preserve_aspect_ratio: 0 or 1, if set to 1, fill the specified width and height as much as possible without stretching the image +# file: Empty string or file type like "application/json" or ".js". +# legacy: 1 to send one giant control sequence, 0 to send many small control sequences. +function print_image() { + # Send metadata to begin transfer. + print_osc + printf "1337;" + if [[ "$9" -eq 1 ]]; then + printf "File" + else + printf "MultipartFile" + fi + printf "=inline=%s" "$2" + printf ";size=%d" $(printf "%s" "$3" | b64_decode | wc -c) + [ -n "$1" ] && printf ";name=%s" "$(printf "%s" "$1" | b64_encode)" + [ -n "$5" ] && printf ";width=%s" "$5" + [ -n "$6" ] && printf ";height=%s" "$6" + [ -n "$7" ] && printf ";preserveAspectRatio=%s" "$7" + [ -n "$8" ] && printf ";type=%s" "$8" + if [[ "$9" -eq 1 ]]; then + printf ":%s" "$3" + print_st + else + print_st + + # Split into 200-byte chunks. This helps it get through tmux. + parts=$(printf "%s" "$3" | fold -w 200) + + # Send each part. + for part in $parts; do + print_osc + printf '1337;FilePart=%s' "$part" + print_st + done + + # Indicate completion + print_osc + printf '1337;FileEnd' + print_st + fi + + printf '\n' + [ "$4" == "1" ] && echo "$1" + has_image_displayed=t +} + +function error() { + errcho "ERROR: $*" +} + +function errcho() { + echo "$@" >&2 +} + +function show_help() { + errcho + errcho "Usage: imgcat [-p] [-n] [-W width] [-H height] [-r] [-s] [-u] [-t file-type] [-f] filename ..." + errcho " cat filename | imgcat [-W width] [-H height] [-r] [-s]" + errcho + errcho "Display images inline in the iTerm2 using Inline Images Protocol" + errcho + errcho "Options:" + errcho + errcho " -h, --help Display help message" + errcho " -p, --print Enable printing of filename or URL after each image" + errcho " -n, --no-print Disable printing of filename or URL after each image" + errcho " -u, --url Interpret following filename arguments as remote URLs" + errcho " -f, --file Interpret following filename arguments as regular Files" + errcho " -t, --type file-type Provides a type hint" + errcho " -r, --preserve-aspect-ratio When scaling image preserve its original aspect ratio" + errcho " -s, --stretch Stretch image to specified width and height (this option is opposite to -r)" + errcho " -W, --width N Set image width to N character cells, pixels or percent (see below)" + errcho " -H, --height N Set image height to N character cells, pixels or percent (see below)" + errcho " -l, --legacy Use legacy protocol that sends the whole image in a single control sequence" + errcho + errcho " If you don't specify width or height an appropriate value will be chosen automatically." + errcho " The width and height are given as word 'auto' or number N followed by a unit:" + errcho " N character cells" + errcho " Npx pixels" + errcho " N% percent of the session's width or height" + errcho " auto the image's inherent size will be used to determine an appropriate dimension" + errcho + errcho " If a type is provided, it is used as a hint to disambiguate." + errcho " The file type can be a mime type like text/markdown, a language name like Java, or a file extension like .c" + errcho " The file type can usually be inferred from the extension or its contents. -t is most useful when" + errcho " a filename is not available, such as whe input comes from a pipe." + errcho + errcho "Examples:" + errcho + errcho " $ imgcat -W 250px -H 250px -s avatar.png" + errcho " $ cat graph.png | imgcat -W 100%" + errcho " $ imgcat -p -W 500px -u http://host.tld/path/to/image.jpg -W 80 -f image.png" + errcho " $ cat url_list.txt | xargs imgcat -p -W 40 -u" + errcho " $ imgcat -t application/json config.json" + errcho +} + +function check_dependency() { + if ! (builtin command -V "$1" >/dev/null 2>&1); then + error "missing dependency: can't find $1" + exit 1 + fi +} + +# verify that value is in the image sizing unit format: N / Npx / N% / auto +function validate_size_unit() { + if [[ ! "$1" =~ ^(:?[0-9]+(:?px|%)?|auto)$ ]]; then + error "Invalid image sizing unit - '$1'" + show_help + exit 1 + fi +} + +## Main + +if [ -t 0 ]; then + has_stdin=f +else + has_stdin=t +fi + +# Show help if no arguments and no stdin. +if [ $has_stdin = f ] && [ $# -eq 0 ]; then + show_help + exit +fi + +check_dependency base64 +check_dependency wc +file_type="" +legacy=0 + +# Look for command line flags. +while [ $# -gt 0 ]; do + case "$1" in + -h | --h | --help) + show_help + exit + ;; + -p | --p | --print) + print_filename=1 + ;; + -n | --n | --no-print) + print_filename=0 + ;; + -W | --W | --width) + validate_size_unit "$2" + width="$2" + shift + ;; + -H | --H | --height) + validate_size_unit "$2" + height="$2" + shift + ;; + -r | --r | --preserve-aspect-ratio) + preserve_aspect_ratio=1 + ;; + -s | --s | --stretch) + preserve_aspect_ratio=0 + ;; + -l | --l | --legacy) + legacy=1 + ;; + -f | --f | --file) + has_stdin=f + is_url=f + ;; + -u | --u | --url) + check_dependency curl + has_stdin=f + is_url=t + ;; + -t | --t | --type) + file_type="$2" + shift + ;; + -*) + error "Unknown option flag: $1" + show_help + exit 1 + ;; + *) + if [ "$is_url" == "t" ]; then + encoded_image=$(curl -fs "$1" | b64_encode) || { + error "Could not retrieve image from URL $1, error_code: $?" + exit 2 + } + elif [ -r "$1" ]; then + encoded_image=$(cat "$1" | b64_encode) + else + error "imgcat: $1: No such file or directory" + exit 2 + fi + has_stdin=f + print_image "$1" 1 "$encoded_image" "$print_filename" "$width" "$height" "$preserve_aspect_ratio" "$file_type" "$legacy" + ;; + esac + shift +done + +# Read and print stdin +if [ $has_stdin = t ]; then + print_image "" 1 "$(cat | b64_encode)" 0 "$width" "$height" "$preserve_aspect_ratio" "$file_type" "$legacy" +fi + +if [ "$has_image_displayed" != "t" ]; then + error "No image provided. Check command line options." + show_help + exit 1 +fi + +exit 0 diff --git a/fedora/.local/bin/lastnvim b/fedora/.local/bin/lastfiles index b1ab6c9..082b004 100755 --- a/fedora/.local/bin/lastnvim +++ b/fedora/.local/bin/lastfiles @@ -2,14 +2,14 @@ # Display help message usage() { - echo "Open the most recent file or the list of old files in fzf edited by nvim." + echo "Open the most recent file or the list of old files in fzf edited by Vim." echo "" echo "Usage: ${0##*/} [OPTION]" echo "" echo "Options:" - echo " : Open the most recent old file in Neovim." + echo " : Open the most recent old file in Vim." echo " -h, --help : Show this help message." - echo " -l, --list : Show all recent files in Neovim using fzf." + echo " -l, --list : Show all recent files in Vim using fzf." echo "" echo "Examples:" echo " ${0##*/} # Open the most recent file." @@ -17,14 +17,20 @@ usage() { exit 0 } +# Fetch oldfiles from Vim +get_oldfiles() { + vim -u NONE -es +'silent oldfiles' +qa 2>/dev/null | + sed 's/^[0-9]\+\s\+//' | + grep -v "^$" +} + # List and handle oldfiles list_oldfiles() { - # Fetch the oldfiles list from Neovim - oldfiles=$(nvim -u NONE --headless +'lua io.write(table.concat(vim.v.oldfiles, "\n") .. "\n")' +qa) + oldfiles=$(get_oldfiles) # Exit if no oldfiles are found [ -z "$oldfiles" ] && { - echo "No recent files found in Neovim." >&2 + echo "No recent files found in Vim." >&2 exit 1 } @@ -33,18 +39,15 @@ list_oldfiles() { usage ;; -l | --list) - # Filter valid files valid_files=$(echo "$oldfiles" | while IFS= read -r file; do [ -f "$file" ] && printf "%s\n" "$file" done) - # Exit if no valid files exist [ -z "$valid_files" ] && { echo "No valid files found." >&2 exit 1 } - # Use fzf to select files selected_files=$(echo "$valid_files" | fzf-tmux \ --multi \ @@ -52,14 +55,12 @@ list_oldfiles() { --height=70% \ --reverse) - # Exit if no files were selected [ -z "$selected_files" ] && exit 1 - # Open selected files in Neovim - openfiles "$selected_files" + openfiles $selected_files ;; *) - # Open the most recent file + # Open the most recent valid file for file in $oldfiles; do if [ -f "$file" ]; then openfiles "$file" diff --git a/fedora/.local/bin/openfiles b/fedora/.local/bin/openfiles index 5b4f7e2..f35aef1 100755 --- a/fedora/.local/bin/openfiles +++ b/fedora/.local/bin/openfiles @@ -1,7 +1,7 @@ #!/bin/sh -if ! command -v nvim >/dev/null 2>&1; then - echo "Error: 'nvim' is not installed." >&2 +if ! command -v vim >/dev/null 2>&1; then + echo "Error: 'vim' is not installed." >&2 exit 1 fi @@ -20,15 +20,15 @@ count=$# case "$count" in 2) - ${EDITOR:-nvim} -O +'silent! normal g;' "$@" -c 'wincmd t' + ${EDITOR:-vim} -O +'silent! normal g;' "$@" -c 'wincmd t' ;; 3) - ${EDITOR:-nvim} -O "$1" -c 'wincmd j' -c "silent! vsplit $2" -c "silent! split $3" -c 'wincmd t' + ${EDITOR:-vim} -O "$1" -c 'wincmd j' -c "silent! vsplit $2" -c "silent! split $3" -c 'wincmd t' ;; 4) - ${EDITOR:-nvim} -O "$1" -c "silent! vsplit $2" -c "silent! split $3" -c 'wincmd h' -c "silent! split $4" -c 'wincmd t' + ${EDITOR:-vim} -O "$1" -c "silent! vsplit $2" -c "silent! split $3" -c 'wincmd h' -c "silent! split $4" -c 'wincmd t' ;; *) - ${EDITOR:-nvim} "$@" + ${EDITOR:-vim} "$@" ;; esac diff --git a/fedora/.local/bin/restartnvim b/fedora/.local/bin/restartvim index ab040ab..3c63f8b 100755 --- a/fedora/.local/bin/restartnvim +++ b/fedora/.local/bin/restartvim @@ -15,11 +15,11 @@ fi # Get the current tmux pane ID tmux_pane=$(tmux display-message -p '#D') -# Send Escape, :wq, and Enter to Neovim in the tmux pane +# Send Escape, :wq, and Enter to Vim in the tmux pane tmux send-keys -t "$tmux_pane" Escape C-m ':wq' C-m -# Wait to ensure Neovim exits +# Wait to ensure Vim exits sleep 0.5 -# Detach the script from Neovim and wait a bit to ensure Neovim exits -(nohup sh -c "sleep 0.5; tmux send-keys -t \"$tmux_pane\" 'nvim -c \"execute \\\"edit \\\" . v:oldfiles[0] | normal '\''0\"' C-m" >/dev/null 2>&1 &) +# Detach the script from Vim and wait a bit to ensure Vim exits +(nohup sh -c "sleep 0.5; tmux send-keys -t \"$tmux_pane\" 'vim -c \"execute \\\"edit \\\" . v:oldfiles[0] | normal '\''0\"' C-m" >/dev/null 2>&1 &) diff --git a/fedora/.local/bin/rg b/fedora/.local/bin/rg Binary files differnew file mode 100755 index 0000000..477c475 --- /dev/null +++ b/fedora/.local/bin/rg diff --git a/fedora/.local/bin/rga b/fedora/.local/bin/rga Binary files differnew file mode 100755 index 0000000..545efba --- /dev/null +++ b/fedora/.local/bin/rga diff --git a/fedora/.local/bin/rga-fzf b/fedora/.local/bin/rga-fzf Binary files differnew file mode 100755 index 0000000..7b86d75 --- /dev/null +++ b/fedora/.local/bin/rga-fzf diff --git a/fedora/.local/bin/rga-fzf-open b/fedora/.local/bin/rga-fzf-open Binary files differnew file mode 100755 index 0000000..71257cd --- /dev/null +++ b/fedora/.local/bin/rga-fzf-open diff --git a/fedora/.local/bin/rga-preproc b/fedora/.local/bin/rga-preproc Binary files differnew file mode 100755 index 0000000..c1ce02f --- /dev/null +++ b/fedora/.local/bin/rga-preproc diff --git a/fedora/.local/bin/sesh b/fedora/.local/bin/sesh Binary files differnew file mode 100755 index 0000000..0355f00 --- /dev/null +++ b/fedora/.local/bin/sesh diff --git a/fedora/.local/bin/sessionizer b/fedora/.local/bin/sessionizer new file mode 100755 index 0000000..93f32b1 --- /dev/null +++ b/fedora/.local/bin/sessionizer @@ -0,0 +1,36 @@ +#!/bin/sh + +sessionizer() { + path="$( + sesh list -d --icons | fzf-tmux \ + -p 80%,70% --no-sort --cycle --ignore-case --ansi --border=sharp --multi --reverse \ + --border-label "╢ TheSiahxyz ╟" \ + --header "^a all ^e sesh ^f zoxide ^g git ^t tmux ^u staged files ^x tmux kill M-cr open in editor ^/ help" \ + --prompt "💡 " \ + --bind "ctrl-a:change-prompt(💡 )+reload(sesh list -d -H --icons)" \ + --bind "ctrl-e:change-prompt(📑 )+reload(sesh list -d -c -H --icons)" \ + --bind "ctrl-f:change-prompt(🔎 )+reload(sesh list -d -z -H --icons)" \ + --bind "ctrl-g:change-prompt( )+reload(fd -H -d 1 -d -t d -E .Trash -E .git -E .cache . $HOME/Private/repos $HOME/Public/repos | sed 's|$HOME|~|g')" \ + --bind "ctrl-t:change-prompt(🪟 )+reload(sesh list -d -t --icons)" \ + --bind "ctrl-v:execute($EDITOR ${0})+abort" \ + --bind 'ctrl-x:execute(tmux kill-session -t "$(echo {} | cut -d" " -f2-)")+reload(sesh list -d --icons)' \ + --bind "alt-enter:execute($EDITOR {})+abort" \ + --bind 'ctrl-/:change-prompt(❓ )+reload(echo "^a all +^e sesh config +^f zoxide +^g git +^t tmux +^x tmux kill +M-cr open in editor +^/ help")' \ + --preview-window 'right:45%' \ + --preview 'sesh preview {}' + )" 2>/dev/null + + case "$path" in + ^*) sessionizer ;; + *) sesh connect "$path" >/dev/null 2>&1 && exit ;; + esac +} + +sessionizer diff --git a/fedora/.local/bin/tmuxopen b/fedora/.local/bin/tmuxopen index 5362215..87e4f36 100755 --- a/fedora/.local/bin/tmuxopen +++ b/fedora/.local/bin/tmuxopen @@ -16,7 +16,7 @@ wrapper() { echo " Ctrl+d Search directories" echo "" echo "Environment Variables:" - echo " NVIM_SEARCH_REGISTRY Set to the search query, allowing Neovim to highlight matches" + echo " VIM_SEARCH_REGISTRY Set to the search query, allowing Neovim to highlight matches" echo "" echo "Example:" echo " tmuxopen # Run the normal search and open" @@ -79,32 +79,32 @@ wrapper() { --prompt "🔎 " } - set_nvim_search_variable() { + set_vim_search_variable() { raw_output="$1" tmp_content_query="/tmp/search-content-query-$$" if [ -f "$tmp_content_query" ]; then saved_query=$(cat "$tmp_content_query" 2>/dev/null) if [ -n "$saved_query" ]; then - export NVIM_SEARCH_REGISTRY="$saved_query" + export VIM_SEARCH_REGISTRY="$saved_query" return fi fi query=$(echo "$raw_output" | head -n1) - export NVIM_SEARCH_REGISTRY="$query" + export VIM_SEARCH_REGISTRY="$query" } - open_files_in_nvim() { + open_files_in_vim() { pane="$1" shift file_indices="$*" - nvim_cmd="nvim" + vim_cmd="vim" for index in $file_indices; do file=$(echo "$files" | awk -v idx="$index" '{print $idx}') line=$(echo "$lines" | awk -v idx="$index" '{print $idx}') - nvim_cmd="$nvim_cmd +$line $file" + vim_cmd="$vim_cmd +$line $file" done - nvim_cmd="$nvim_cmd -c 'let @/=\"$NVIM_SEARCH_REGISTRY\"'" - tmux send-keys -t "$pane" "$nvim_cmd" C-m + vim_cmd="$vim_cmd -c 'let @/=\"$VIM_SEARCH_REGISTRY\"'" + tmux send-keys -t "$pane" "$vim_cmd" C-m } # Parse command line arguments @@ -123,7 +123,7 @@ wrapper() { done raw_output=$(get_fzf_output) - set_nvim_search_variable "$raw_output" + set_vim_search_variable "$raw_output" # Split the newline-delimited output into an array, skipping the first line (query) selections=$(echo "$raw_output" | sed 1d) @@ -158,42 +158,42 @@ EOF fi if [ "$count" -eq 1 ]; then - open_files_in_nvim "$(tmux display-message -p '#P')" 1 + open_files_in_vim "$(tmux display-message -p '#P')" 1 else window_name="$(date +%s)" tmux new-window -n "$window_name" case "$count" in 2) tmux split-window -t "$window_name" -h -p 50 - open_files_in_nvim "$window_name.1" 1 - open_files_in_nvim "$window_name.2" 2 + open_files_in_vim "$window_name.1" 1 + open_files_in_vim "$window_name.2" 2 tmux select-pane -t "$window_name.1" ;; 3) tmux split-window -t "$window_name" -h -p 50 tmux split-window -t "$window_name.2" -v -p 50 - open_files_in_nvim "$window_name.1" 1 - open_files_in_nvim "$window_name.2" 2 - open_files_in_nvim "$window_name.3" 3 + open_files_in_vim "$window_name.1" 1 + open_files_in_vim "$window_name.2" 2 + open_files_in_vim "$window_name.3" 3 ;; *) tmux split-window -t "$window_name" -h -p 50 tmux split-window -t "$window_name.1" -v -p 50 tmux split-window -t "$window_name.3" -v -p 50 - open_files_in_nvim "$window_name.1" 1 - open_files_in_nvim "$window_name.2" 2 - open_files_in_nvim "$window_name.3" 3 + open_files_in_vim "$window_name.1" 1 + open_files_in_vim "$window_name.2" 2 + open_files_in_vim "$window_name.3" 3 remaining_indices="" for i in $(seq 4 "$count"); do remaining_indices="$remaining_indices $i" done - open_files_in_nvim "$window_name.4" "$remaining_indices" + open_files_in_vim "$window_name.4" "$remaining_indices" ;; esac fi } -for cmd in rg fzf bat tmux nvim; do +for cmd in rg fzf bat tmux vim; do if ! command -v $cmd >/dev/null 2>&1; then echo "Error: $cmd not found" >&2 exit 1 diff --git a/fedora/.local/bin/ya b/fedora/.local/bin/ya Binary files differnew file mode 100755 index 0000000..2701e30 --- /dev/null +++ b/fedora/.local/bin/ya diff --git a/fedora/.local/bin/yazi b/fedora/.local/bin/yazi Binary files differnew file mode 100755 index 0000000..0c01561 --- /dev/null +++ b/fedora/.local/bin/yazi diff --git a/fedora/.local/bin/zoxide b/fedora/.local/bin/zoxide Binary files differnew file mode 100755 index 0000000..e7ba833 --- /dev/null +++ b/fedora/.local/bin/zoxide |
