diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-12-07 18:16:05 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-12-07 18:16:05 +0900 |
| commit | 5ff02959d3069923bca63cb54c4bb246b86bf20d (patch) | |
| tree | 7ef1b56fb85a48c563bb3af51c26f181741282be /fedora/.local | |
| parent | f65fe7591c18d6c8f4ecac5f379407a910aba1bc (diff) | |
deleted .gnupg/gpg-agent.conf, created .gnupg/, created .config/, created .local/, created .gnupg/
Diffstat (limited to 'fedora/.local')
| -rwxr-xr-x | fedora/.local/bin/bookmarks | 211 | ||||
| -rwxr-xr-x | fedora/.local/bin/extract | 41 | ||||
| -rwxr-xr-x | fedora/.local/bin/lastnvim | 77 | ||||
| -rwxr-xr-x | fedora/.local/bin/openfiles | 34 | ||||
| -rwxr-xr-x | fedora/.local/bin/opensessions | 37 | ||||
| -rwxr-xr-x | fedora/.local/bin/remaps | 69 | ||||
| -rwxr-xr-x | fedora/.local/bin/restartnvim | 25 | ||||
| -rwxr-xr-x | fedora/.local/bin/rgafiles | 120 | ||||
| -rwxr-xr-x | fedora/.local/bin/shortcuts | 87 | ||||
| -rwxr-xr-x | fedora/.local/bin/tmuxcreate | 42 | ||||
| -rwxr-xr-x | fedora/.local/bin/tmuxcycleborder | 7 | ||||
| -rwxr-xr-x | fedora/.local/bin/tmuxopen | 208 | ||||
| -rwxr-xr-x | fedora/.local/bin/tmuxtogglebar | 6 | ||||
| -rwxr-xr-x | fedora/.local/bin/tmuxtoggleterm | 11 |
14 files changed, 975 insertions, 0 deletions
diff --git a/fedora/.local/bin/bookmarks b/fedora/.local/bin/bookmarks new file mode 100755 index 0000000..a892a33 --- /dev/null +++ b/fedora/.local/bin/bookmarks @@ -0,0 +1,211 @@ +#!/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/extract b/fedora/.local/bin/extract new file mode 100755 index 0000000..b352a70 --- /dev/null +++ b/fedora/.local/bin/extract @@ -0,0 +1,41 @@ +#!/bin/sh + +# Default behavior: Extract archive into new directory +# Behavior with `-c` option: Extract contents into current directory + +while getopts "hc" o; do case "${o}" in + c) extracthere="True" ;; + *) printf 'Options:\n -c: Extract archive into current directory rather than a new one.\n' && exit ;; + esac done + +if [ -z "$extracthere" ]; then + archive="$(readlink -f "$*")" && + directory=${archive%.*} && + mkdir -p "$directory" && + cd "$directory" || exit +else + archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)")" +fi + +[ "$archive" = "" ] && printf 'Give archive to extract as argument.\n' && exit + +if [ -f "$archive" ]; then + case "$archive" in + *.tar.bz2 | *.tar.xz | *.tbz2) tar xvjf "$archive" ;; + *.tar.gz | *.tgz) tar xvzf "$archive" ;; + *.lzma) unlzma "$archive" ;; + *.bz2) bunzip2 "$archive" ;; + *.rar) unrar x -ad "$archive" ;; + *.gz) gunzip "$archive" ;; + *.tar) tar xvf "$archive" ;; + *.zip | *.jar | *.war) unzip "$archive" ;; + *.Z) uncompress "$archive" ;; + *.7z) 7z x "$archive" ;; + *.xz) unxz "$archive" ;; + *.exe) cabextract "$archive" ;; + *.ace) unace x "$archive" ;; + *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;; + esac +else + printf 'File "%s" not found.\n' "$archive" +fi diff --git a/fedora/.local/bin/lastnvim b/fedora/.local/bin/lastnvim new file mode 100755 index 0000000..b1ab6c9 --- /dev/null +++ b/fedora/.local/bin/lastnvim @@ -0,0 +1,77 @@ +#!/bin/sh + +# Display help message +usage() { + echo "Open the most recent file or the list of old files in fzf edited by nvim." + echo "" + echo "Usage: ${0##*/} [OPTION]" + echo "" + echo "Options:" + echo " : Open the most recent old file in Neovim." + echo " -h, --help : Show this help message." + echo " -l, --list : Show all recent files in Neovim using fzf." + echo "" + echo "Examples:" + echo " ${0##*/} # Open the most recent file." + echo " ${0##*/} -l # Show all recent files in fzf and select to open." + exit 0 +} + +# 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) + + # Exit if no oldfiles are found + [ -z "$oldfiles" ] && { + echo "No recent files found in Neovim." >&2 + exit 1 + } + + case "$1" in + -h | --help) + 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 \ + --preview 'bat -n --color=always --line-range=:500 {} 2>/dev/null || echo "Error previewing file"' \ + --height=70% \ + --reverse) + + # Exit if no files were selected + [ -z "$selected_files" ] && exit 1 + + # Open selected files in Neovim + openfiles "$selected_files" + ;; + *) + # Open the most recent file + for file in $oldfiles; do + if [ -f "$file" ]; then + openfiles "$file" + exit 0 + fi + done + + echo "No valid recent files found." >&2 + exit 1 + ;; + esac +} + +# Parse command-line arguments +list_oldfiles "$@" diff --git a/fedora/.local/bin/openfiles b/fedora/.local/bin/openfiles new file mode 100755 index 0000000..5b4f7e2 --- /dev/null +++ b/fedora/.local/bin/openfiles @@ -0,0 +1,34 @@ +#!/bin/sh + +if ! command -v nvim >/dev/null 2>&1; then + echo "Error: 'nvim' is not installed." >&2 + exit 1 +fi + +IFS=' +' + +files=$* + +for file in $files; do + files_list="$files_list \"$(realpath "$file")\"" +done + +eval "set -- $files_list" + +count=$# + +case "$count" in +2) + ${EDITOR:-nvim} -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' + ;; +4) + ${EDITOR:-nvim} -O "$1" -c "silent! vsplit $2" -c "silent! split $3" -c 'wincmd h' -c "silent! split $4" -c 'wincmd t' + ;; +*) + ${EDITOR:-nvim} "$@" + ;; +esac diff --git a/fedora/.local/bin/opensessions b/fedora/.local/bin/opensessions new file mode 100755 index 0000000..6f9f236 --- /dev/null +++ b/fedora/.local/bin/opensessions @@ -0,0 +1,37 @@ +#!/bin/sh + +# split the selected directories into an array +dirs="$*" + +# filter out any empty selections +dirs=$(echo "$dirs" | tr -s ' ' '\n' | sed '/^$/d') +[ -z "$dirs" ] && exit 0 + +# function to clean and create a valid session name +get_session_name() { + basename "$1" | sed 's/[^a-zA-Z0-9]/_/g' +} + +set -- $dirs + +# handle session creation for multiple selected directories +for dir in $dirs; do + if [ -d "$dir" ]; then + session_name=$(get_session_name "$dir") + if ! tmux has-session -t "$session_name" 2>/dev/null; then + tmux new-session -d -s "$session_name" -c "$dir" + if git -C "$dir" rev-parse --is-inside-work-tree >/dev/null 2>&1 && [ -n "$(git -C "$dir" status --porcelain)" ]; then + tmux send-keys -t "$session_name" "git status --porcelain" C-m + fi + fi + fi +done + +if [ "$#" -gt 0 ]; then + first_session=$(get_session_name "$1") + if [ -n "$TMUX" ]; then + tmux switch-client -t "$first_session" + else + tmux attach-session -t "$first_session" + fi +fi diff --git a/fedora/.local/bin/remaps b/fedora/.local/bin/remaps new file mode 100755 index 0000000..93832ea --- /dev/null +++ b/fedora/.local/bin/remaps @@ -0,0 +1,69 @@ +#!/bin/sh + +# This script is called on startup to remap keys. +xset s off -dpms +# Decrease key repeat delay to 200ms and increase key repeat rate to 50 per second. +xset r rate 200 50 +# Map the caps lock key to control, and map the menu key to right super. +xinput list | grep 'id=' | while read -r line; do + keyboard=$(echo "$line" | grep -i 'keyboard.*id.*keyboard' | sed 's/.*id=\([0-9]\+\).*/\1/') + mouse=$(echo "$line" | grep -i '.*id.*pointer' | sed 's/.*id=\([0-9]\+\).*/\1/') + [ -z "$keyboard" ] || { + case "$(echo "$line" | grep -oE '.*id=' | sed 's/ id=.*//')" in + *"Lite-On Tech Lenovo USB Travel Keyboard with Ultra Nav"*) + setxkbmap -device "$keyboard" -option + setxkbmap -device "$keyboard" -option caps:ctrl_modifier,ctrl:swap_lwin_lctl + ;; + *"Lite-On Technology Corp. ThinkPad USB Keyboard with TrackPoint"* | *"AT Translated Set 2 keyboard"*) + setxkbmap -device "$keyboard" -option + setxkbmap -device "$keyboard" -option caps:ctrl_modifier,altwin:menu_win,altwin:swap_lalt_lwin + ;; + *"Magic keyboard"*) + setxkbmap -device "$keyboard" -option + setxkbmap -device "$keyboard" -option caps:ctrl_modifier + ;; + *"HHKB"*) + setxkbmap -device "$keyboard" -option + setxkbmap -device "$keyboard" -option altwin:menu_win + ;; + *"Glove80"*) + setxkbmap -device "$keyboard" -option + ;; + *) + setxkbmap -device "$keyboard" -option + setxkbmap -device "$keyboard" -option caps:ctrl_modifier,altwin:menu_win + ;; + esac + } + [ -z "$mouse" ] || { + case "$(echo "$line" | grep -oE '.*id=' | sed 's/ id=.*//')" in + *"Apple Inc. Magic Trackpad"*) + xinput set-prop "$mouse" "libinput Tapping Enabled" 0 + ;; + *"SynPS/2 Synaptics TouchPad"*) + xinput set-prop "$mouse" "libinput Tapping Enabled" 0 + ;; + *"Lite-On Tech Lenovo USB Travel Keyboard with Ultra Nav Mouse"*) + [ -z "$1" ] && xinput set-prop "$mouse" "Coordinate Transformation Matrix" 5, 0, 0, 0, 5, 0, 0, 0, 1 || xinput set-prop "$mouse" "Coordinate Transformation Matrix" $1, 0, 0, 0, $1, 0, 0, 0, 1 + xinput set-prop "$mouse" "libinput Scroll Method Enabled" 0, 0, 1 + ;; + *"Logitech USB Receiver"*) + [ -z "$1" ] && xinput set-prop "$mouse" "Coordinate Transformation Matrix" 3, 0, 0, 0, 3, 0, 0, 0, 1 || xinput set-prop "$mouse" "Coordinate Transformation Matrix" $1, 0, 0, 0, $1, 0, 0, 0, 1 + ;; + *"TPPS/2 IBM TrackPoint"*) + [ -z "$1" ] && xinput set-prop "$mouse" "Coordinate Transformation Matrix" 1, 0, 0, 0, 1, 0, 0, 0, 1 || xinput set-prop "$mouse" "Coordinate Transformation Matrix" $1, 0, 0, 0, $1, 0, 0, 0, 1 + ;; + *"Lite-On Technology Corp. ThinkPad USB Keyboard with TrackPoint"*) + [ -z "$1" ] && xinput set-prop "$mouse" "Coordinate Transformation Matrix" 3, 0, 0, 0, 3, 0, 0, 0, 1 || xinput set-prop "$mouse" "Coordinate Transformation Matrix" $1, 0, 0, 0, $1, 0, 0, 0, 1 + ;; + *"Glove80 Mouse"*) + [ -z "$1" ] && xinput set-prop "$mouse" "Coordinate Transformation Matrix" 2, 0, 0, 0, 2, 0, 0, 0, 1 || xinput set-prop "$mouse" "Coordinate Transformation Matrix" $1, 0, 0, 0, $1, 0, 0, 0, 1 + ;; + esac + } +done +# When left control, caps lock, or Super_L is pressed only once, treat it as escape. +killall xcape 2>/dev/null +xcape -e 'Caps_Lock=Escape;Control_L=Escape' #;Super_L=Escape' +# Turn off caps lock if on since there is no longer a key for it. +xset -q | grep -q "Caps Lock:\s*on" && xdotool key Caps_Lock diff --git a/fedora/.local/bin/restartnvim b/fedora/.local/bin/restartnvim new file mode 100755 index 0000000..ab040ab --- /dev/null +++ b/fedora/.local/bin/restartnvim @@ -0,0 +1,25 @@ +#!/bin/sh + +set -e + +# Set new line and tab for word splitting +IFS=" + " + +# Check if the script is running inside a tmux session +if [ -z "$TMUX" ]; then + echo "This script must be run from inside a tmux session." + exit 1 +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 +tmux send-keys -t "$tmux_pane" Escape C-m ':wq' C-m + +# Wait to ensure Neovim 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 &) diff --git a/fedora/.local/bin/rgafiles b/fedora/.local/bin/rgafiles new file mode 100755 index 0000000..e8b5e72 --- /dev/null +++ b/fedora/.local/bin/rgafiles @@ -0,0 +1,120 @@ +#!/bin/sh + +# Usage function to display script options +usage() { + echo "Find files using ripgrep and open them in Neovim." + echo "" + echo "Usage: ${0##*/} [-s] [-i] [-l] [-p] [<tag>] <query>" + echo "" + echo "Options:" + echo " -h : Show this message" + echo " -i : Perform a case-insensitive search (default)" + echo " -l : List files associated with the given tag" + echo " -p : Search for files in the specified project directories using the specified tag (default: PROJECT)" + echo " -s : Perform a case-sensitive search" + echo " [<tag>] <query> : Optional tag for project mode, followed by the search query" + echo "" + echo "Examples:" + echo " ${0##*/} -p TODO 'KEYWORD' # Search for 'KEYWORD' in files tagged with 'TODO' in the project directories" + echo " ${0##*/} -l -p 'KEYWORD' # List files associated with the default 'PROJECT' tag and 'KEYWORD'" + echo " ${0##*/} 'KEYWORD' # Open files containing 'KEYWORD' in nvim" + exit 0 +} + +search_term() { + case_flag="$1" + shift + + if ! command -v rga >/dev/null 2>&1; then + echo "Error: 'rga' is not installed." >&2 + exit 1 + fi + if ! command -v xclip >/dev/null 2>&1; then + echo "Error: 'xclip' is not installed." >&2 + exit 1 + fi + + # Construct the preview command + preview_cmd=$(printf "rga %s --pretty --context 10 '%s' {}" "$case_flag" "$*") + rga_output=$(rga --follow --no-ignore --hidden --text --max-count=1 ${case_flag:+$case_flag} --files-with-matches --no-messages --glob '!**/.git/*' "$*") + + # Use fzf to select files + files=$(echo "$rga_output" | fzf-tmux +m --preview="$preview_cmd" --reverse --multi --select-1 --exit-0) || return 1 + + # Check if files are selected + if [ -z "$files" ]; then + echo "No files selected." + return 0 + fi + + # copy target to the clipboard + echo "$@" | xclip -selection clipboard 2>/dev/null + + openfiles "$files" + + # print the file names + echo "$rga_output" +} + +# Function to list and/or open all files associated with a given project tag +list_or_open_project_files() { + # Use the provided tag or default to "PROJECT" + project_tag="${1:-PROJECT}: $2" + + # Define the project paths as a space-separated string + project_paths="$HOME/.dotfiles $HOME/.local/src/suckless $HOME/Public/repos" + + # Use rga to find files containing the project tag across all project paths + rga_output="" + for path in $project_paths; do + if [ -d "$path" ]; then + rga_result=$(rga --follow --no-ignore --hidden --text --max-count=1 --files-with-matches --no-messages --glob '!**/.git/*' "$project_tag" "$path") + rga_output="$rga_output $rga_result" + fi + done + + # Remove leading/trailing whitespace + rga_output=$(echo "$rga_output" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + + # Check if any files were found + if [ -z "$rga_output" ]; then + echo "No files found for tag $project_tag." + return 0 + fi + + # If the script was called in list mode, simply print the files + if [ "$list_mode" -eq 1 ]; then + echo "$rga_output" + else + # Otherwise, open the files with nvim + set -- "$(printf "%s\n" "$rga_output")" + openfiles "$@" + fi +} + +# Main function to handle options +case_flag="--ignore-case" # Default to case-insensitive +list_mode=0 +project_mode=0 + +# Parse the options +while getopts "silph" opt; do + case $opt in + s) case_flag="--case-sensitive" ;; # Case-sensitive + i) case_flag="--ignore-case" ;; # Case-insensitive + l) list_mode=1 ;; # List mode + p) project_mode=1 ;; # Project mode + h) usage ;; + *) ;; + esac +done + +shift $((OPTIND - 1)) + +# Handle project mode search +if [ "$project_mode" -eq 1 ]; then + list_or_open_project_files "$1" "$2" +else + # Otherwise, call the common search function + search_term "$case_flag" "$@" +fi diff --git a/fedora/.local/bin/shortcuts b/fedora/.local/bin/shortcuts new file mode 100755 index 0000000..ab5e69d --- /dev/null +++ b/fedora/.local/bin/shortcuts @@ -0,0 +1,87 @@ +#!/bin/sh + +bmdirs="${XDG_CONFIG_HOME:-${HOME}/.config}/shell/bm-dirs" +bmfiles="${XDG_CONFIG_HOME:-${HOME}/.config}/shell/bm-files" + +# Output locations. Unactivated progs should go to /dev/null. +shell_shortcuts="${XDG_CONFIG_HOME:-${HOME}/.config}/shell/shortcutrc" +shell_env_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutenvrc" +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" +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 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" + +# Remove, prepare files +rm -f "$lf_shortcuts" "$ranger_shortcuts" "$qute_shortcuts" "$zsh_named_dirs" "$vim_shortcuts" "$nvim_shortcuts" "$yazi_shortcuts" 2>/dev/null +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" + +# Format the `directories` file in the correct syntax and sent it to all three configs. +eval "echo \"$(cat "$bmdirs")\"" | + awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); + printf(\"%s=\42cd %s && ls -A\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"[ -n \42%s\42 ] && export %s=\42%s\42 \n\",\$1,\$1,\$2) >> \"$shell_env_shortcuts\" ; + printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; + printf(\"abbr %s \42cd %s; and ls -A\42\n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"map g%s :cd %s<CR>\nmap t%s <tab>:cd %s<CR><tab>\nmap M%s <tab>:cd %s<CR><tab>:mo<CR>\nmap Y%s <tab>:cd %s<CR><tab>:co<CR> \n\",\$1,\$2, \$1, \$2, \$1, \$2, \$1, \$2) >> \"$vifm_shortcuts\" ; + printf(\"config.bind(',,%s', \42set downloads.location.directory %s ;; hint links download\42) \n\",\$1,\$2) >> \"$qute_shortcuts\" ; + printf(\"map g%s cd %s\nmap t%s tab_new %s\nmap m%s shell mv -v %%s %s\nmap Y%s shell cp -rv %%s %s \n\",\$1,\$2,\$1,\$2, \$1, \$2, \$1, \$2) >> \"$ranger_shortcuts\" ; + printf(\"map %s cd \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" ; + printf(\"cmap ;%s %s\n\",\$1,\$2) >> \"$vim_shortcuts\" ; + printf(\"nmap <localleader><localleader>%s :Explore %s<cr>\n\",\$1,\$2) >> \"$vim_shortcuts\" ; + desc_path = \$2; gsub(\"^/home/$USER/\",\"~/\",desc_path); + printf(\"vim.keymap.set('c', ';%s', '%s<cr>', { noremap = true, silent = true, desc = '%s' })\n\", \$1, \$2, desc_path) >> \"$nvim_shortcuts\" ; + printf(\"vim.keymap.set('n', '<localleader><leader>%s', '<cmd>Explore %s<cr>', { noremap = true, silent = true, desc = '%s' })\n\", \$1, \$2, desc_path) >> \"$nvim_shortcuts\" ; + 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\"}" + +# Format the `files` file in the correct syntax and sent it to both configs. +eval "echo \"$(cat "$bmfiles")\"" | + awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); + printf(\"%s=\42\$EDITOR %s\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"[ -n \42%s\42 ] && export %s=\42%s\42 \n\",\$1,\$1,\$2) >> \"$shell_env_shortcuts\" ; + printf(\"v%s=\42\$EDITOR2 %s\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; + printf(\"abbr %s \42\$EDITOR %s\42 \n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"abbr v%s \42\$EDITOR2 %s\42 \n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"map %s :e %s<CR> \n\",\$1,\$2) >> \"$vifm_shortcuts\" ; + printf(\"map %s shell \$EDITOR %s \n\",\$1,\$2) >> \"$ranger_shortcuts\" ; + printf(\"map v%s shell \$EDITOR2 %s \n\",\$1,\$2) >> \"$ranger_shortcuts\" ; + printf(\"map %s \$\$EDITOR \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" ; + printf(\"map v%s \$\$EDITOR2 \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" ; + printf(\"cmap ;%s %s\n\",\$1,\$2) >> \"$vim_shortcuts\" ; + printf(\"nmap <localleader><localleader>%s :e %s<cr>\n\",\$1,\$2) >> \"$vim_shortcuts\" ; + desc_path = \$2; gsub(\"^/home/$USER/\",\"~/\",desc_path); + printf(\"vim.keymap.set('c', ';%s', '%s<cr>', { noremap = true, silent = true, desc = '%s' })\n\", \$1, \$2, desc_path) >> \"$nvim_shortcuts\" ; + 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\" }" + +# Merge bookmarks into keymap-default.toml +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) + + # Create the merged file + 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" + 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" +fi diff --git a/fedora/.local/bin/tmuxcreate b/fedora/.local/bin/tmuxcreate new file mode 100755 index 0000000..5fb5ef3 --- /dev/null +++ b/fedora/.local/bin/tmuxcreate @@ -0,0 +1,42 @@ +#!/bin/sh + +create_new_session() { + session_name=$1 + session_path=${2:-"$PWD"} # Default to current directory if no path is provided + [ -z "$session_name" ] && { printf "New session name: " && read -r session_name; } + if tmux has-session -t "$session_name" 2>/dev/null; then + tmux switch-client -t "$session_name" + else + if [ -n "$TMUX" ]; then + tmux new-session -d -s "$session_name" -c "$session_path" + tmux switch-client -t "$session_name" + else + tmux new -s "$session_name" -c "$session_path" + fi + fi +} + +if [ $# -gt 0 ]; then + if [ -d "$1" ]; then + create_new_session "$(basename "$1")" "$1" + else + create_new_session "$1" + fi +else + # Capture the output of tmux ls + sessions=$(tmux ls 2>/dev/null) + if [ -z "$sessions" ]; then + create_new_session + else + session=$( ( + echo "$sessions" + echo "[new session]" + ) | fzf-tmux --reverse | cut -d: -f1) + [ -z "$session" ] && exit + if [ "$session" = "[new session]" ]; then + create_new_session + else + tmux attach -t "$session" + fi + fi +fi diff --git a/fedora/.local/bin/tmuxcycleborder b/fedora/.local/bin/tmuxcycleborder new file mode 100755 index 0000000..ad2a430 --- /dev/null +++ b/fedora/.local/bin/tmuxcycleborder @@ -0,0 +1,7 @@ +#!/bin/sh + +case "$(tmux show-option -gqv pane-border-status)" in +"off") tmux set-option -g pane-border-status top ;; +"top") tmux set-option -g pane-border-status bottom ;; +"bottom") tmux set-option -g pane-border-status off ;; +esac diff --git a/fedora/.local/bin/tmuxopen b/fedora/.local/bin/tmuxopen new file mode 100755 index 0000000..5362215 --- /dev/null +++ b/fedora/.local/bin/tmuxopen @@ -0,0 +1,208 @@ +#!/bin/sh + +wrapper() { + usage() { + echo "Search for files and open them in Neovim within tmux panes." + echo "" + echo "Usage: tmuxopen [OPTIONS]" + echo "" + echo "Options:" + echo " -h, --help : Show this help message" + echo "" + echo "Controls:" + echo " Tab Select files" + echo " Ctrl+f Search filenames" + echo " Ctrl+g Search file contents" + echo " Ctrl+d Search directories" + echo "" + echo "Environment Variables:" + echo " NVIM_SEARCH_REGISTRY Set to the search query, allowing Neovim to highlight matches" + echo "" + echo "Example:" + echo " tmuxopen # Run the normal search and open" + } + + get_fzf_output() { + # Create temporary files to store search state + tmp_files="/tmp/search-files-$$" + tmp_content_query="/tmp/search-content-query-$$" + + # Cleanup on exit + trap "rm -f $tmp_files $tmp_content_query" EXIT + + rg_fixed_bind="ctrl-g:transform-query( + echo {q} > $tmp_content_query; + echo {q} + )+reload( + rm -f $tmp_files; + rg --line-number --follow --fixed-strings --hidden --no-heading --color=always --smart-case --glob '!**/.git/**' --glob '!node_modules/**' {q} 2>/dev/null || true + )" + file_bind="ctrl-f:transform-query( + current_query={q}; + if [ ! -s $tmp_content_query ]; then + echo \$current_query > $tmp_content_query; + fi; + rg --hidden --follow --files-with-matches --no-messages --glob '!**/.git/**' --glob '!node_modules/**' -- \$current_query > $tmp_files; + )+reload( + if [ -s $tmp_files ]; then + if [ -n {q} ]; then + grep -i -- {q} $tmp_files || true; + else + cat $tmp_files; + fi | while IFS= read -r file; do + if [ -f \"\$file\" ]; then + echo \"\$file:1\"; + fi; + done; + else + echo 'No matching files found'; + fi + )" + if command -v fd >/dev/null 2>&1; then + dir_bind="ctrl-d:change-prompt(📁 )+reload(fd --follow --type d --hidden --absolute-path --color never --exclude .git --exclude node_modules --search-path \"\$PWD\")" + else + dir_bind="ctrl-d:change-prompt(📁 )+reload(find \"\$PWD\" -L -type d -name node_modules -prune -o -name .git -prune -o -type d -print)" + fi + + rg --line-number --follow --no-heading --color=always --smart-case --glob '!**/.git/**' --glob '!LICENSE' '' 2>/dev/null | + fzf-tmux \ + --ansi --multi --delimiter : \ + --reverse \ + --print-query \ + --preview 'bat --style=numbers --color=always --highlight-line {2} {1} 2>/dev/null || bat --color=always {} 2>/dev/null || ls -la {} 2>/dev/null || echo "Preview is not available."' \ + --preview-window 'right,55%,border-bottom,+{2}+3/3,~3' \ + --bind "$file_bind" \ + --bind "$rg_fixed_bind" \ + --bind "$dir_bind" \ + --bind 'ctrl-c:abort' \ + --header "^f filenames | ^g contents | ^d directories" \ + --prompt "🔎 " + } + + set_nvim_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" + return + fi + fi + query=$(echo "$raw_output" | head -n1) + export NVIM_SEARCH_REGISTRY="$query" + } + + open_files_in_nvim() { + pane="$1" + shift + file_indices="$*" + nvim_cmd="nvim" + 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" + done + nvim_cmd="$nvim_cmd -c 'let @/=\"$NVIM_SEARCH_REGISTRY\"'" + tmux send-keys -t "$pane" "$nvim_cmd" C-m + } + + # Parse command line arguments + while [ "$#" -gt 0 ]; do + case "$1" in + -h | --help) + usage + exit 0 + ;; + *) + echo "Unknown option: $1" >&2 + usage + exit 1 + ;; + esac + done + + raw_output=$(get_fzf_output) + set_nvim_search_variable "$raw_output" + + # Split the newline-delimited output into an array, skipping the first line (query) + selections=$(echo "$raw_output" | sed 1d) + + if [ -z "$selections" ]; then + echo "No selections made" + exit 0 + fi + + files="" + lines="" + count=0 + + # Use a here document to avoid subshell issues + while IFS= read -r selection; do + file=$(echo "$selection" | awk -F: '{print $1}') + line=$(echo "$selection" | awk -F: '{print $2}') + if [ -f "$file" ]; then + files="$files $file" + lines="$lines $line" + count=$((count + 1)) + else + echo "File not found: $file" + fi + done <<EOF +$selections +EOF + + if [ "$count" -eq 0 ]; then + echo "No valid files selected" + exit 0 + fi + + if [ "$count" -eq 1 ]; then + open_files_in_nvim "$(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 + 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 + ;; + *) + 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 + remaining_indices="" + for i in $(seq 4 "$count"); do + remaining_indices="$remaining_indices $i" + done + open_files_in_nvim "$window_name.4" "$remaining_indices" + ;; + esac + fi +} + +for cmd in rg fzf bat tmux nvim; do + if ! command -v $cmd >/dev/null 2>&1; then + echo "Error: $cmd not found" >&2 + exit 1 + fi +done + +if [ -z "$TMUX" ]; then + echo "Error: Not in a tmux session" >&2 + exit 1 +fi + +wrapper "$@" diff --git a/fedora/.local/bin/tmuxtogglebar b/fedora/.local/bin/tmuxtogglebar new file mode 100755 index 0000000..2ae045e --- /dev/null +++ b/fedora/.local/bin/tmuxtogglebar @@ -0,0 +1,6 @@ +#!/bin/sh + +case "$(tmux show-option -gqv status)" in +on) tmux set-option -g status off ;; +off) tmux set-option -g status on ;; +esac diff --git a/fedora/.local/bin/tmuxtoggleterm b/fedora/.local/bin/tmuxtoggleterm new file mode 100755 index 0000000..f21f833 --- /dev/null +++ b/fedora/.local/bin/tmuxtoggleterm @@ -0,0 +1,11 @@ +#!/bin/sh + +export TMUX_PANE_DIRECTION="bottom" + +if [ "$TMUX_PANE_DIRECTION" = "bottom" ]; then + tmux select-pane -U +elif [ "$TMUX_PANE_DIRECTION" = "right" ]; then + tmux select-pane -L +fi + +tmux resize-pane -Z |
