-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.common.shrc
More file actions
121 lines (106 loc) · 3.09 KB
/
Copy path.common.shrc
File metadata and controls
121 lines (106 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
source "$HOME"/.shinit
[ -s "$HOME"/.sensitive.shrc ] && source "$HOME"/.sensitive.shrc # export OPENAI_API_KEY
# Put all configurations that are not universally applicable into this file.
[ -s "$HOME"/.machine_specific.shrc ] && source "$HOME"/.machine_specific.shrc
alias ds="{du -sh *; du -sh ./} | sort -rh " #diskspace
alias normalize_unicode='convmv -r -f utf-8 -t utf-8 --notest --nfc'
backup() {
case $1 in
-h|--help|'')
printf "Usage: %s files|folders...\n" "$0"
return 0
;;
*)
for it in "$@"
do
cp "${it}"{,.bak}
done
;;
esac
}
# Search all file types including pdf, ppt, and open grepped files
grepOpen() {
RG_PREFIX="rga --files-with-matches"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
--phony -q "$1" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
)" &&
echo "opening $file" &&
open "$file"
}
# Search filenames and open them
findOpen() {
local file
file="$(fzf)" &&
echo "opening $file" &&
open "$file"
}
transfer() {
local url=https://transfer.sixtyfive.me
if [ $# -eq 0 ]
then
echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>" >&2
return 1
fi
if tty -s
then
file="$1"
file_name=$(basename "$file")
if [ ! -e "$file" ]
then
echo "$file: No such file or directory" >&2
return 1
fi
if [ -d "$file" ]
then
file_name="$file_name.zip"
(
pushd "$file" && zip -r -q - .
) | curl --progress-bar --upload-file "-" "$url/$(urlencode $file_name)" | tee /dev/null
else
cat "$file" | curl --progress-bar --upload-file "-" "$url/$(urlencode $file_name)" | tee /dev/null
fi
else
file_name=$1
curl --progress-bar --upload-file "-" "$url/$(urlencode $file_name)" | tee /dev/null
fi
}
# Advanced fzf configuration
# Define common exclusions
_fzf_exclusions=(".git" "node_modules" "__pycache__" ".venv")
# Create a function to generate the exclusion options for fd
_fzf_fd_exclude() {
local exclude_opts=""
for dir in "${_fzf_exclusions[@]}"; do
exclude_opts+=" --exclude \"$dir\""
done
echo "$exclude_opts"
}
# Invoked when a user types `<command> **<tab>`, where <command> is not `cd`
_fzf_compgen_path() {
eval fd $( _fzf_fd_exclude ) --type f --hidden --follow . "$1" 2>/dev/null
}
# Invoked when a user types `cd **<tab>`
_fzf_compgen_dir() {
eval fd $( _fzf_fd_exclude ) --type d --hidden --follow . "$1" 2>/dev/null
}
# Advanced customization of fzf options via _fzf_comprun function
# - The first argument to the function is the name of the command.
# - You should make sure to pass the rest of the arguments to fzf.
_fzf_comprun() {
__fzf_comprun__command__=$1
shift
case "$__fzf_comprun__command__" in
cd) fzf --preview 'tree -C {} | head -200' "$@" ;;
export | unset) fzf --preview "eval 'echo \$'{}" "$@" ;;
ssh) fzf --preview 'dig {}' "$@" ;;
*) fzf --preview 'bat -n --color=always {}' "$@" ;;
esac
}
# Node version management is handled by mise in shims mode (see ~/.shinit); the
# old nvm bash_completion is no longer sourced.