-
Notifications
You must be signed in to change notification settings - Fork 0
/
.shinit
245 lines (200 loc) · 5.83 KB
/
.shinit
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env sh
# sh (POSIX) compatible configs
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export MANPATH="$HOME"/.local/share/man:/usr/share/man:"$MANPATH"
# set PATH so it includes user's private bin if it exists
LOCALBIN="$HOME/.local/bin"
case "$PATH" in
"*$LOCALBIN*") ;;
*) PATH="$LOCALBIN:$PATH" ;;
esac
SNAPBIN="/snap/bin"
case "$PATH" in
"*$SNAPBIN*") ;;
*) PATH="$SNAPBIN:$PATH" ;;
esac
M1_SILICON_BREW_PATH="/opt/homebrew/bin"
case "$PATH" in
"*$M1_SILICON_BREW_PATH*") ;;
*) PATH="$M1_SILICON_BREW_PATH:$PATH" ;;
esac
BREW_PACKAGES_PATH=$HOME/.paths
if [ -f "$BREW_PACKAGES_PATH" ]; then
NEW_PATHS=$(cat "$BREW_PACKAGES_PATH")
PATH=$NEW_PATHS:$PATH
fi
if command -v nproc >/dev/null 2>&1; then
HOMEBREW_MAKE_JOBS="$(nproc --all)"
else
HOMEBREW_MAKE_JOBS=4
fi
export HOMEBREW_MAKE_JOBS
export LD_LIBRARY_PATH="$HOME"/.local/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
[ -n "$DISPLAY" ] && export XAUTHORITY="$HOME"/.Xauthority
EDITOR="$(command -v nvim || command -v vim || printf 'vi')"
export EDITOR
# Alias's to modified commands
if command -v rsync >/dev/null 2>&1; then
alias cp='rsync -ah --info=progress2 --old-args'
# `--old-args` is added for rsync > 3.2.4.
# Whereas the latest rsync does not need double-escape backslashes to handle remote paths,
# zsh-provided completion file still assume rsync need double-escaped baskslashes.
# Please refer to https://askubuntu.com/a/1495090 for more details.
fi
alias ls='ls --human-readable --color=always'
alias ll='ls --human-readable -l --all --classify --size'
alias scp='scp -r'
alias mv='mv -i'
alias rm='rm -iv'
alias mkdir='mkdir -p'
alias ps='ps auxf'
alias ping='ping -c 10'
alias less='less -R'
alias lessn='less -R -N'
alias cls='clear'
alias vi='vim'
alias svi='sudo vi'
alias vis='vim "+set si"'
alias tmux='tmux -2' #force 256 colors
alias psed='perl -pe' #sed with pcre support
alias fd='fd --hidden' #find dotfiles as well
alias rg='rg --auto-hybrid-regex' #Always allow look-ahead/behind
if command -v prename >/dev/null 2>&1; then
alias rename=prename
fi
export BAT_THEME=gruvbox-dark
alias c='clear'
ocr() {
tesseract -l kor+eng "$@" stdout
}
check_text_file() {
filepath="$1"
# Use the `file` command to check the file type
file_output=$(file --brief --mime-type "$filepath")
# Check if the file output contains "text"
case "$file_output" in
text/*)
echo "The file is a text file."
return 0
;;
application/json*)
echo "The file is a text file."
return 0
;;
*)
echo "The file is not a text file."
return 1
;;
esac
}
mkrand() {
# Create a new directory with a name based on the current time and a random suffix,
# then change into that directory.
current_time=$(date -u +"%Y-%m-%d")
random_suffix=$(tr -dc 'a-zA-Z' </dev/urandom | head -c 6)
folder_name="${current_time}_${random_suffix}"
mkdir "${folder_name}";
cd "${folder_name}" || exit 1
}
# Alias of xdg-open, and ignore stderr
open() {
# If a file is a text file, open it with the editor
if check_text_file "$1" >/dev/null; then
$EDITOR "$1"
return
fi
# Use the appropriate command for the platform to open other files
if [ "$(uname)" = "Darwin" ]; then
/usr/bin/open "$@"
else
xdg-open "$@" 2>/dev/null
fi
}
alias gpull='git pull --rebase origin'
alias gpush='git push origin'
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gcm='git commit -m'
alias gf='git fetch'
alias gb='git branch'
alias gck='git checkout'
alias glog='git log --all --decorate --oneline --graph'
alias gd='git difftool'
alias grm='git add -u'
countfiles() {
for t in files links directories; do
printf "%d\t%s\n" "$(find . -type "$(echo "$t" | cut -c1)" | wc -l)" "$t"
done 2>/dev/null
}
alias folders='du -h --max-depth=1'
alias folderssort='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn'
alias tree='tree -CAhF --dirsfirst'
alias treed='tree -CAFd'
mountedinfo() {
case $1 in
-h | --help)
printf "Shows mounted file system information\n"
printf "Usage: %s [--all]\n" "$0"
;;
-a | --all)
df --human-readable --print-type
;;
*)
df --human-readable --print-type --type ext4
;;
esac
}
# Search files in the current folder
alias f="find ."
# alias chmod commands
alias mx='chmod a+x'
alias 000='chmod -R 000'
alias 644='chmod -R 644'
alias 666='chmod -R 666'
alias 755='chmod -R 755'
alias 777='chmod -R 777'
#alias htop="htop -u $(whoami)"
alias htop="htop -s PERCENT_CPU"
alias qq='tmux kill-window'
if command -v nvim >/dev/null 2>&1; then
alias vim=nvim
alias vimdiff='nvim -d'
fi
if command -v viddy >/dev/null 2>&1; then
alias watch='viddy -s -d'
fi
export FZF_DEFAULT_OPTS='-m --bind=ctrl-space:toggle,tab:down,shift-tab:up'
if command -v bfs >/dev/null 2>&1; then
export FZF_DEFAULT_COMMAND='bfs -follow'
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND -type d 2> /dev/null"
elif command -v fd >/dev/null 2>&1; then
export FZF_DEFAULT_COMMAND='fd --follow'
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND --type d 2> /dev/null"
fi
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND 2> /dev/null"
if command -v gdircolors >/dev/null 2>&1; then
eval "$(gdircolors "$HOME"/.dircolors)"
else
eval "$(dircolors "$HOME"/.dircolors)"
fi
# Load sdkman
[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ] && . "$HOME/.sdkman/bin/sdkman-init.sh"
if [ -f "$HOME/.cargo/env" ]; then
. "$HOME/.cargo/env"
fi
if [ -d "$HOME/.cargo/bin" ]; then
PATH=$PATH:$HOME/.cargo/bin
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
export KUBECONFIG="$HOME"/.kube/config
command -v javac >/dev/null 2>&1 && export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
unset LC_ALL
export LC_MESSAGES="en_US.UTF-8"
export LANG="ko_KR.UTF-8"
export LC_COLLATE="ko_KR.UTF-8"
export LC_CTYPE=en_US.UTF-8 # For k9s ascii diagram
export LC_MONETARY="ko_KR.UTF-8"
export LC_NUMERIC="ko_KR.UTF-8"
export LC_TIME="ko_KR.UTF-8"