some changes

This commit is contained in:
pika 2024-08-16 14:51:56 +02:00
parent 4b60c50202
commit 5a11540bf8
2 changed files with 495 additions and 486 deletions

30
.bashrc
View file

@ -9,10 +9,10 @@ function echo_info() { echo -e "\033[0;35m${*}\033[0m"; }
# for examples # for examples
# If not running interactively, don't do anything # If not running interactively, don't do anything
case $- in # case $- in
*i*) ;; # *i*) ;;
*) return ;; # *) return ;;
esac # esac
_defaults_() { _defaults_() {
# don't put duplicate lines or lines starting with space in the history. # don't put duplicate lines or lines starting with space in the history.
@ -269,15 +269,6 @@ _cat_() {
fi fi
} }
_fzf_() {
if command_exists fzf; then
# Set up fzf key bindings and fuzzy completion
eval "$(fzf --bash)"
source ./fzf-bash-completion.sh
bind -x '"\t": fzf_bash_completion'
fi
}
_fetches_() { _fetches_() {
# ─< fastfetch >──────────────────────────────────────────────────────────────────────────── # ─< fastfetch >────────────────────────────────────────────────────────────────────────────
if command_exists fastfetch; then if command_exists fastfetch; then
@ -289,9 +280,7 @@ _fetches_() {
git clone https://git.k4li.de/mirrors/fastfetch.git $HOME/.local/share/fastfetch >/dev/null 2>&1 git clone https://git.k4li.de/mirrors/fastfetch.git $HOME/.local/share/fastfetch >/dev/null 2>&1
exec $SHELL exec $SHELL
fi fi
clear & alias clear="clear & ff"
f
alias clear="clear & f"
fi fi
} }
@ -386,9 +375,11 @@ get_packager() {
refresh="nala update" refresh="nala update"
remove="nala remove" remove="nala remove"
purge="nala purge" purge="nala purge"
search="nala search"
alias update="$_sudo $refresh && $_sudo $upgrade" alias update="$_sudo $refresh && $_sudo $upgrade"
alias install="$_sudo $refresh && $_sudo $install" alias install="$_sudo $refresh && $_sudo $install"
alias remove="$_sudo $remove && $_sudo $purge && $_sudo $clean" alias remove="$_sudo $remove && $_sudo $purge && $_sudo $clean"
alias search="$search"
elif command_exists apt-get; then elif command_exists apt-get; then
PKG="apt-get" PKG="apt-get"
install="apt-get install --yes" install="apt-get install --yes"
@ -397,9 +388,11 @@ get_packager() {
clean="apt-get autoremove" clean="apt-get autoremove"
remove="apt-get remove" remove="apt-get remove"
purge="apt-get purge" purge="apt-get purge"
search="apt-cache search"
alias update="$_sudo $refresh && $_sudo $upgrade" alias update="$_sudo $refresh && $_sudo $upgrade"
alias install="$_sudo $refresh && $_sudo $install" alias install="$_sudo $refresh && $_sudo $install"
alias remove="$_sudo $remove && $_sudo $purge && $_sudo $clean" alias remove="$_sudo $remove && $_sudo $purge && $_sudo $clean"
alias search="$search"
fi fi
;; ;;
arch | manjaro | endevouros) arch | manjaro | endevouros)
@ -408,16 +401,19 @@ get_packager() {
alias install="yay -S --noconfirm" alias install="yay -S --noconfirm"
alias update="yay -Syu" alias update="yay -Syu"
alias remove="yay -R" alias remove="yay -R"
alias search="yay -Ss"
elif command_exists paru; then elif command_exists paru; then
PKG="paru" PKG="paru"
alias install="paru -S --noconfirm" alias install="paru -S --noconfirm"
alias update="paru -Syu" alias update="paru -Syu"
alias remove="paru -R" alias remove="paru -R"
alias search="paru -Ss"
elif command_exists pacman; then elif command_exists pacman; then
PKG="pacman" PKG="pacman"
alias install="$_sudo pacman -S --noconfirm" alias install="$_sudo pacman -S --noconfirm"
alias update="$_sudo pacman -Syu" alias update="$_sudo pacman -Syu"
alias remove="$_sudo pacman -R" alias remove="$_sudo pacman -R"
alias search="$_sudo pacman -Ss"
fi fi
;; ;;
fedora | centos) fedora | centos)
@ -425,6 +421,7 @@ get_packager() {
alias install="dnf install --yes" alias install="dnf install --yes"
alias update="dnf update" alias update="dnf update"
alias remove="dnf remove" alias remove="dnf remove"
alias search="dnf search"
;; ;;
alpine) alpine)
PKG="apk" PKG="apk"
@ -445,7 +442,6 @@ get_alias() {
_color_prompt_ _color_prompt_
_cli_qol_ _cli_qol_
_cat_ _cat_
# _fzf_
_trash _trash
_nmap_ _nmap_
_tmux_ _tmux_

View file

@ -1,9 +1,9 @@
_FZF_COMPLETION_SEP=$'\x01' _FZF_COMPLETION_SEP=$'\x01'
# shell parsing stuff # shell parsing stuff
_fzf_bash_completion_awk="$( builtin command -v gawk &>/dev/null && echo gawk || echo awk )" _fzf_bash_completion_awk="$(builtin command -v gawk &>/dev/null && echo gawk || echo awk)"
_fzf_bash_completion_sed="$( builtin command -v gsed &>/dev/null && echo gsed || echo sed )" _fzf_bash_completion_sed="$(builtin command -v gsed &>/dev/null && echo gsed || echo sed)"
_fzf_bash_completion_grep="$( builtin command -v ggrep &>/dev/null && echo ggrep || echo builtin command grep )" _fzf_bash_completion_grep="$(builtin command -v ggrep &>/dev/null && echo ggrep || echo builtin command grep)"
_fzf_bash_completion_awk_escape() { _fzf_bash_completion_awk_escape() {
"$_fzf_bash_completion_sed" 's/\\/\\\\\\\\/g; s/[[*^$.]/\\\\&/g' <<<"$1" "$_fzf_bash_completion_sed" 's/\\/\\\\\\\\/g; s/[[*^$.]/\\\\&/g' <<<"$1"
@ -32,13 +32,13 @@ _fzf_bash_completion_flatten_subshells() {
local count=0 buffer= local count=0 buffer=
while IFS= read -r line; do while IFS= read -r line; do
case "$line" in case "$line" in
\(|\{) (( count -- )) ;; \( | \{) ((count--)) ;;
\)|\}) (( count ++ )) ;; \) | \}) ((count++)) ;;
esac esac
if (( count < 0 )); then if ((count < 0)); then
return return
elif (( count > 0 )); then elif ((count > 0)); then
buffer="$line$buffer" buffer="$line$buffer"
else else
printf '%s\n' "$line$buffer" printf '%s\n' "$line$buffer"
@ -53,13 +53,13 @@ _fzf_bash_completion_find_matching_bracket() {
local count=0 local count=0
while IFS=: read -r num bracket; do while IFS=: read -r num bracket; do
if [ "$bracket" = "$1" ]; then if [ "$bracket" = "$1" ]; then
(( count++ )) ((count++))
if (( count > 0 )); then if ((count > 0)); then
printf '%s\n' "$num" printf '%s\n' "$num"
return 0 return 0
fi fi
else else
(( count -- )) ((count--))
fi fi
done < <($_fzf_bash_completion_grep -F -e '(' -e ')' -n) done < <($_fzf_bash_completion_grep -F -e '(' -e ')' -n)
return 1 return 1
@ -78,10 +78,10 @@ _fzf_bash_completion_parse_dq() {
shell_start="$(<<<"$line" $_fzf_bash_completion_grep -E -o '^(\\.|\$[^(]|[^$])*\$\(')" shell_start="$(<<<"$line" $_fzf_bash_completion_grep -E -o '^(\\.|\$[^(]|[^$])*\$\(')"
string_end="$(<<<"$line" $_fzf_bash_completion_grep -E -o '^(\\.|[^"])*"')" string_end="$(<<<"$line" $_fzf_bash_completion_grep -E -o '^(\\.|[^"])*"')"
if (( ${#string_end} && ( ! ${#shell_start} || ${#string_end} < ${#shell_start} ) )); then if ((${#string_end} && (!${#shell_start} || ${#string_end} < ${#shell_start}))); then
# found end of string # found end of string
line="${line:${#string_end}}" line="${line:${#string_end}}"
if (( ${#line} )); then if ((${#line})); then
printf '%s\n' "${words:0:-${#line}}" printf '%s\n' "${words:0:-${#line}}"
_fzf_bash_completion_parse_line <<<"$line" _fzf_bash_completion_parse_line <<<"$line"
else else
@ -89,7 +89,7 @@ _fzf_bash_completion_parse_dq() {
fi fi
return return
elif (( ${#shell_start} && ( ! ${#string_end} || ${#shell_start} < ${#string_end} ) )); then elif ((${#shell_start} && (!${#string_end} || ${#shell_start} < ${#string_end}))); then
# found a subshell # found a subshell
word+="${shell_start:0:-2}" word+="${shell_start:0:-2}"
@ -142,11 +142,12 @@ _fzf_bash_completion_unquote_strings() {
} }
_fzf_bash_completion_parse_line() { _fzf_bash_completion_parse_line() {
_fzf_bash_completion_shell_split \ _fzf_bash_completion_shell_split |
| _fzf_bash_completion_parse_dq \ _fzf_bash_completion_parse_dq |
| _fzf_bash_completion_flatten_subshells \ _fzf_bash_completion_flatten_subshells |
| tr \\n \\0 \ tr \\n \\0 |
| "$_fzf_bash_completion_sed" -r "$(cat <<'EOF' "$_fzf_bash_completion_sed" -r "$(
cat <<'EOF'
# collapse newlines # collapse newlines
s/\x00\x00/\x00/g; s/\x00\x00/\x00/g;
# leave trailing space # leave trailing space
@ -162,8 +163,8 @@ s/^(.*[\x00\n])?(\[\[|case|do|done|elif|else|esac|fi|for|function|if|in|select|t
# remove ENVVAR=VALUE # remove ENVVAR=VALUE
s/^(\s*[\n\x00]|\w+=[^\n\x00]*[\n\x00])*// s/^(\s*[\n\x00]|\w+=[^\n\x00]*[\n\x00])*//
EOF EOF
)" \ )" |
| tr \\0 \\n tr \\0 \\n
} }
_fzf_bash_completion_compspec() { _fzf_bash_completion_compspec() {
@ -203,7 +204,7 @@ _fzf_bash_completion_complete_variables() {
local brace="${BASH_REMATCH[1]}" local brace="${BASH_REMATCH[1]}"
local filter="${BASH_REMATCH[2]}" local filter="${BASH_REMATCH[2]}"
if [ -n "$filter" ]; then if [ -n "$filter" ]; then
local prefix="${2:: -${#filter}}" local prefix="${2::-${#filter}}"
else else
local prefix="$2" local prefix="$2"
fi fi
@ -247,26 +248,26 @@ fzf_bash_completion() {
# remove the ones that just spaces # remove the ones that just spaces
local i local i
# iterate in reverse # iterate in reverse
for (( i = ${#COMP_WORDS[@]}-2; i >= 0; i --)); do for ((i = ${#COMP_WORDS[@]} - 2; i >= 0; i--)); do
if ! [[ "${COMP_WORDS[i]}" =~ [^[:space:]] ]]; then if ! [[ "${COMP_WORDS[i]}" =~ [^[:space:]] ]]; then
COMP_WORDS=( "${COMP_WORDS[@]:0:i}" "${COMP_WORDS[@]:i+1}" ) COMP_WORDS=("${COMP_WORDS[@]:0:i}" "${COMP_WORDS[@]:i+1}")
fi fi
done done
# add an extra blank word if last word is just space # add an extra blank word if last word is just space
if [[ "${#COMP_WORDS[@]}" = 0 ]]; then if [[ "${#COMP_WORDS[@]}" = 0 ]]; then
COMP_WORDS+=( '' ) COMP_WORDS+=('')
elif ! [[ "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" =~ [^[:space:]] ]]; then elif ! [[ "${COMP_WORDS[${#COMP_WORDS[@]} - 1]}" =~ [^[:space:]] ]]; then
COMP_WORDS[${#COMP_WORDS[@]}-1]='' COMP_WORDS[${#COMP_WORDS[@]} - 1]=''
fi fi
COMP_CWORD="${#COMP_WORDS[@]}" COMP_CWORD="${#COMP_WORDS[@]}"
(( COMP_CWORD-- )) ((COMP_CWORD--))
local cmd="${COMP_WORDS[0]}" local cmd="${COMP_WORDS[0]}"
local prev local prev
if [ "$COMP_CWORD" = 0 ]; then if [ "$COMP_CWORD" = 0 ]; then
prev= prev=
else else
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD - 1]}"
fi fi
local cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" =~ ^[$wordbreaks]$ ]]; then if [[ "$cur" =~ ^[$wordbreaks]$ ]]; then
@ -281,7 +282,7 @@ fzf_bash_completion() {
line="${line::-${#raw_cur}}" line="${line::-${#raw_cur}}"
fi fi
READLINE_LINE="${line}${COMPREPLY}${READLINE_LINE:$READLINE_POINT}" READLINE_LINE="${line}${COMPREPLY}${READLINE_LINE:$READLINE_POINT}"
(( READLINE_POINT+=${#COMPREPLY} - ${#raw_cur} )) ((READLINE_POINT += ${#COMPREPLY} - ${#raw_cur}))
fi fi
printf '\r' printf '\r'
@ -290,15 +291,15 @@ fzf_bash_completion() {
_fzf_bash_completion_selector() { _fzf_bash_completion_selector() {
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" \ FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" \
$(__fzfcmd 2>/dev/null || echo fzf) -1 -0 --prompt "${FZF_TAB_COMPLETION_PROMPT:-> }$line" --nth 2 -d "$_FZF_COMPLETION_SEP" --ansi \ $(__fzfcmd 2>/dev/null || echo fzf) -1 -0 --prompt "${FZF_TAB_COMPLETION_PROMPT:-> }$line" --nth 2 -d "$_FZF_COMPLETION_SEP" --ansi |
| tr -d "$_FZF_COMPLETION_SEP" tr -d "$_FZF_COMPLETION_SEP"
} }
_fzf_bash_completion_expand_alias() { _fzf_bash_completion_expand_alias() {
if alias "$1" &>/dev/null; then if alias "$1" &>/dev/null; then
value=( ${BASH_ALIASES[$1]} ) value=(${BASH_ALIASES[$1]})
if [ -n "${value[*]}" -a "${value[0]}" != "$1" ]; then if [ -n "${value[*]}" -a "${value[0]}" != "$1" ]; then
raw_comp_words=( "${value[@]}" "${raw_comp_words[@]:1}" ) raw_comp_words=("${value[@]}" "${raw_comp_words[@]:1}")
fi fi
fi fi
} }
@ -310,10 +311,10 @@ _fzf_bash_completion_auto_common_prefix() {
prefix_len="${#prefix}" prefix_len="${#prefix}"
prefix_is_full=1 # prefix == item prefix_is_full=1 # prefix == item
input_len="$(( ${#1} ))" input_len="$((${#1}))"
while [ "$prefix_len" != "$input_len" ] && IFS= read -r item && items+=("$item"); do while [ "$prefix_len" != "$input_len" ] && IFS= read -r item && items+=("$item"); do
for ((i=$input_len; i<$prefix_len; i++)); do for ((i = $input_len; i < $prefix_len; i++)); do
if [[ "${item:i:1}" != "${prefix:i:1}" ]]; then if [[ "${item:i:1}" != "${prefix:i:1}" ]]; then
prefix_len="$i" prefix_len="$i"
unset prefix_is_full unset prefix_is_full
@ -328,7 +329,7 @@ _fzf_bash_completion_auto_common_prefix() {
if [ "$prefix_len" != "$input_len" ]; then if [ "$prefix_len" != "$input_len" ]; then
if [ "$FZF_COMPLETION_AUTO_COMMON_PREFIX_PART" == true ] || [ "$prefix_is_full" == 1 ]; then if [ "$FZF_COMPLETION_AUTO_COMMON_PREFIX_PART" == true ] || [ "$prefix_is_full" == 1 ]; then
[ "${items[1]}" ] && printf 'compl_nospace=1\n'>&"${__evaled}" # no space if not only one [ "${items[1]}" ] && printf 'compl_nospace=1\n' >&"${__evaled}" # no space if not only one
printf %s\\n "${prefix:0:prefix_len}" printf %s\\n "${prefix:0:prefix_len}"
return return
fi fi
@ -368,18 +369,18 @@ fzf_bash_completer() {
count=0 count=0
_fzf_bash_completion_complete "$@" _fzf_bash_completion_complete "$@"
while (( $? == 124 )); do while (($? == 124)); do
(( count ++ )) ((count++))
if (( count > 32 )); then if ((count > 32)); then
echo "$1: possible retry loop" >/dev/tty echo "$1: possible retry loop" >/dev/tty
break break
fi fi
_fzf_bash_completion_complete "$@" _fzf_bash_completion_complete "$@"
done done
printf '%s\n' "$_FZF_COMPLETION_SEP$_fzf_sentinel1$_fzf_sentinel2" printf '%s\n' "$_FZF_COMPLETION_SEP$_fzf_sentinel1$_fzf_sentinel2"
) | $_fzf_bash_completion_sed -un "/$_fzf_sentinel1$_fzf_sentinel2/q; p" \ ) | $_fzf_bash_completion_sed -un "/$_fzf_sentinel1$_fzf_sentinel2/q; p" |
| _fzf_bash_completion_auto_common_prefix "$raw_cur" \ _fzf_bash_completion_auto_common_prefix "$raw_cur" |
| _fzf_bash_completion_unbuffered_awk '$0!="" && !x[$0]++' '$0 = "\x1b[37m" substr($0, 1, len) "\x1b[0m" sep substr($0, len+1)' -vlen="${#raw_cur}" -vsep="$_FZF_COMPLETION_SEP" _fzf_bash_completion_unbuffered_awk '$0!="" && !x[$0]++' '$0 = "\x1b[37m" substr($0, 1, len) "\x1b[0m" sep substr($0, len+1)' -vlen="${#raw_cur}" -vsep="$_FZF_COMPLETION_SEP"
) )
local coproc_pid="$COPROC_PID" local coproc_pid="$COPROC_PID"
value="$(_fzf_bash_completion_selector "$1" "$raw_cur" "$3" <&"${COPROC[0]}")" value="$(_fzf_bash_completion_selector "$1" "$raw_cur" "$3" <&"${COPROC[0]}")"
@ -391,7 +392,7 @@ fzf_bash_completer() {
printf 'code=%q\n' "$code" printf 'code=%q\n' "$code"
# kill descendant processes of coproc # kill descendant processes of coproc
descend_process () { descend_process() {
printf '%s\n' "$1" printf '%s\n' "$1"
for pid in $(ps -ef | "$_fzf_bash_completion_awk" -v ppid="$1" '$3 == ppid { print $2 }'); do for pid in $(ps -ef | "$_fzf_bash_completion_awk" -v ppid="$1" '$3 == ppid { print $2 }'); do
descend_process "$pid" descend_process "$pid"
@ -416,41 +417,50 @@ _fzf_bash_completion_complete() {
return return
fi fi
local args=( "$@" ) local args=("$@")
eval "compspec=( $compspec )" eval "compspec=( $compspec )"
set -- "${compspec[@]}" set -- "${compspec[@]}"
shift # remove the complete command shift # remove the complete command
while (( $# > 1 )); do while (($# > 1)); do
case "$1" in case "$1" in
-F) -F)
local compl_function="$2" local compl_function="$2"
shift ;; shift
;;
-C) -C)
local compl_command="$2" local compl_command="$2"
shift ;; shift
;;
-G) -G)
local compl_globpat="$2" local compl_globpat="$2"
shift ;; shift
;;
-W) -W)
local compl_wordlist="$2" local compl_wordlist="$2"
shift ;; shift
;;
-X) -X)
local compl_xfilter="$2" local compl_xfilter="$2"
shift ;; shift
;;
-o) -o)
_fzf_bash_completion_compopt -o "$2" _fzf_bash_completion_compopt -o "$2"
shift ;; shift
;;
-A) -A)
local compgen_opts+=( "$1" "$2" ) local compgen_opts+=("$1" "$2")
shift ;; shift
;;
-P) -P)
local compl_prefix="$(_fzf_bash_completion_awk_escape "$2")" local compl_prefix="$(_fzf_bash_completion_awk_escape "$2")"
shift ;; shift
;;
-S) -S)
local compl_suffix="$(_fzf_bash_completion_awk_escape "$2")" local compl_suffix="$(_fzf_bash_completion_awk_escape "$2")"
shift ;; shift
;;
-[a-z]) -[a-z])
compgen_actions+=( "$1" ) compgen_actions+=("$1")
;; ;;
esac esac
shift shift
@ -508,33 +518,36 @@ _fzf_bash_completion_complete() {
fi fi
printf '\n' printf '\n'
) | _fzf_bash_completion_apply_xfilter "$compl_xfilter" \ ) | _fzf_bash_completion_apply_xfilter "$compl_xfilter" |
| _fzf_bash_completion_unbuffered_awk '$0!=""' 'sub(find, replace)' -vfind='.*' -vreplace="$(printf %s "$compl_prefix" | "$_fzf_bash_completion_sed" 's/[&\]/\\&/g')&$(printf %s "$compl_suffix" | "$_fzf_bash_completion_sed" 's/[&\]/\\&/g')" \ _fzf_bash_completion_unbuffered_awk '$0!=""' 'sub(find, replace)' -vfind='.*' -vreplace="$(printf %s "$compl_prefix" | "$_fzf_bash_completion_sed" 's/[&\]/\\&/g')&$(printf %s "$compl_suffix" | "$_fzf_bash_completion_sed" 's/[&\]/\\&/g')" |
| if IFS= read -r line || (( ${#COMPREPLY[@]} )); then if IFS= read -r line || ((${#COMPREPLY[@]})); then
([[ -z "$line" ]] || printf '%s\n' "$line"; cat) | _fzf_bash_completion_quote_filenames "$@" (
[[ -z "$line" ]] || printf '%s\n' "$line"
cat
) | _fzf_bash_completion_quote_filenames "$@"
else else
# got no results # got no results
local compgen_opts=() local compgen_opts=()
[ "$compl_bashdefault" = 1 ] && compgen_opts+=( -o bashdefault ) [ "$compl_bashdefault" = 1 ] && compgen_opts+=(-o bashdefault)
[ "$compl_default" = 1 ] && compgen_opts+=( -o default ) [ "$compl_default" = 1 ] && compgen_opts+=(-o default)
[ "$compl_dirnames" = 1 ] && compgen_opts+=( -o dirnames ) [ "$compl_dirnames" = 1 ] && compgen_opts+=(-o dirnames)
# don't double invoke fzf # don't double invoke fzf
if [ -n "${compgen_opts[*]}" ]; then if [ -n "${compgen_opts[*]}" ]; then
# these are all filenames # these are all filenames
printf 'compl_filenames=1\n'>&"${__evaled}" printf 'compl_filenames=1\n' >&"${__evaled}"
compgen "${compgen_opts[@]}" -- "$2" \ compgen "${compgen_opts[@]}" -- "$2" |
| compl_filenames=1 _fzf_bash_completion_quote_filenames "$@" \ compl_filenames=1 _fzf_bash_completion_quote_filenames "$@" |
| _fzf_bash_completion_dir_marker _fzf_bash_completion_dir_marker
fi fi
fi fi
if [ "$compl_plusdirs" = 1 ]; then if [ "$compl_plusdirs" = 1 ]; then
compgen -o dirnames -- "$2" \ compgen -o dirnames -- "$2" |
| compl_filenames=1 _fzf_bash_completion_quote_filenames "$@" \ compl_filenames=1 _fzf_bash_completion_quote_filenames "$@" |
| _fzf_bash_completion_dir_marker _fzf_bash_completion_dir_marker
fi fi
) \ ) |
| "$dir_marker" "$dir_marker"
} }
_fzf_bash_completion_apply_xfilter() { _fzf_bash_completion_apply_xfilter() {