diff options
| -rw-r--r-- | fedora/.config/bash/keymaps.bash | 25 | ||||
| -rwxr-xr-x | fedora/.local/bin/rgafiles | 120 |
2 files changed, 8 insertions, 137 deletions
diff --git a/fedora/.config/bash/keymaps.bash b/fedora/.config/bash/keymaps.bash index bbe27a0..e355d20 100644 --- a/fedora/.config/bash/keymaps.bash +++ b/fedora/.config/bash/keymaps.bash @@ -11,15 +11,15 @@ PROMPT_COMMAND='echo -ne "\e[5 q"' # ---------- helper: pre_cmd ---------- pre_cmd() { - local txt="$1" - if [[ -z "${READLINE_LINE+set}" ]]; then - printf '%s ' "$txt" - return + # history에서 가장 마지막 명령어 가져오기 + local last_cmd + last_cmd=$(history 1 | sed 's/^[ ]*[0-9]*[ ]*//') + + # 이미 sudo로 시작하면 그대로 + if [[ $last_cmd != sudo* ]]; then + READLINE_LINE="sudo $last_cmd" + READLINE_POINT=${#READLINE_LINE} fi - local left=${READLINE_LINE:0:READLINE_POINT} - local right=${READLINE_LINE:READLINE_POINT} - READLINE_LINE="${left}${txt} ${right}" - READLINE_POINT=$((READLINE_POINT + ${#txt} + 1)) } # ---------- Clipboard detection ---------- @@ -153,7 +153,6 @@ upd() { command -v upd >/dev/null 2>&1 && upd "$@" || printf 'upd: not found\n' cht() { command -v cht >/dev/null 2>&1 && cht "$@" || printf 'cht: not found\n' >&2; } # from '^ucht' -> 'cht' ali() { command -v ali >/dev/null 2>&1 && ali "$@" || printf 'ali: not found\n' >&2; } fD() { command -v fD >/dev/null 2>&1 && fD "$@" || printf 'fD: not found\n' >&2; } -rgafiles() { command -v rgafiles >/dev/null 2>&1 && rgafiles "$@" || printf 'rgafiles: not found\n' >&2; } lastfiles_l() { command -v lastfiles >/dev/null 2>&1 && lastfiles -l || printf 'lastfiles: not found\n' >&2; } # ---------- Readline key bindings (bind -x) ---------- @@ -201,13 +200,11 @@ __bc() { bc -lq "$@"; } bind -x '"\C-d":cdi' bind -x '"\C-f":fzffiles' -bind -x '"\C-g":lf' bind -x '"\C-n":lastfiles' bind -x '"\C-o":tmo' bind -x '"\C-p":fzfpass' bind -x '"\C-q":htop' bind -x '"\C-t":sessionizer' -bind -x '"\C-y":lfcd' bind -x '"\C-z":upd' # ^_ (Ctrl-_) mapped to cht (from '^ucht' -> 'cht') bind -x $'"\C-_":cht' @@ -217,7 +214,6 @@ bind -x '"\C-x\C-a":ali' bind -x '"\C-x\C-b":gitopenbranch' bind -x '"\C-x\C-d":fD' bind -x '"\C-x\C-f":gitfiles' -bind -x '"\C-x\C-g":rgafiles' bind -x '"\C-x\C-l":gloac' bind -x '"\C-x\C-n":lastfiles_l' bind -x '"\C-x\C-q":fpkill' @@ -225,8 +221,3 @@ bind -x '"\C-x\C-r":fgst' bind -x '"\C-x\C-t":gitstagedfiles' bind -x '"\C-x\C-u":gitupdate' bind -x '"\C-x\C-_":fzffns' # ^X^_ -bind -x '"\C-x\C-x\C-b":rbackup' -bind -x '"\C-x\C-x\C-p":pcyr' -bind -x '"\C-x\C-x\C-r":rbackup' # rbackup -r not directly supported via bind -x args; call rbackup then ask user for flags if needed -bind -x '"\C-x\C-x\C-s":sshadd' -bind -x '"\C-x\C-x\C-y":yay_remaps' diff --git a/fedora/.local/bin/rgafiles b/fedora/.local/bin/rgafiles deleted file mode 100755 index ac4471b..0000000 --- a/fedora/.local/bin/rgafiles +++ /dev/null @@ -1,120 +0,0 @@ -#!/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 vim" - 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 vim - 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 |
