-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshrc.sh
More file actions
135 lines (110 loc) · 3.19 KB
/
shrc.sh
File metadata and controls
135 lines (110 loc) · 3.19 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
# shellcheck disable=SC2155
# Prevent re-sourcing to avoid overriding project aliases
[ -n "$SHRC_SOURCED" ] && return
export SHRC_SOURCED=1
# Setup paths
remove_from_path() {
[ -d "$1" ] || return
PATHSUB=":$PATH:"
PATHSUB=${PATHSUB//:$1:/:}
PATHSUB=${PATHSUB#:}
PATHSUB=${PATHSUB%:}
export PATH="$PATHSUB"
}
add_to_path_start() {
[ -d "$1" ] || return
remove_from_path "$1"
export PATH="$1:$PATH"
}
add_to_path_end() {
[ -d "$1" ] || return
remove_from_path "$1"
export PATH="$PATH:$1"
}
force_add_to_path_start() {
remove_from_path "$1"
export PATH="$1:$PATH"
}
quiet_which() {
command -v "$1" >/dev/null
}
add_to_path_start "/usr/local/sbin"
add_to_path_start "/home/linuxbrew/.linuxbrew/bin"
add_to_path_start "/usr/local/bin"
add_to_path_start "/opt/homebrew/bin"
add_to_path_start "$HOME/.bin"
# Ubuntu-specific paths
if [ -f /etc/lsb-release ] && grep -q "Ubuntu" /etc/lsb-release 2>/dev/null; then
add_to_path_end "$HOME/.local/bin"
fi
# Ghostty terminfo fallback for remote machines without it
if [ "$TERM" = "xterm-ghostty" ] && ! infocmp xterm-ghostty >/dev/null 2>&1; then
export TERM=xterm-256color
fi
# aliases
alias gl='git log --date=short --pretty=format:"%C(124)%ad %C(24)%h %C(34)%an %C(252)%s%C(178)%d" --stat'
alias gsign='git commit -C HEAD -S -s --amend'
alias reset-color="echo -e \"\e[39m\""
alias tmux-main="tmux new-session -A -s main"
if [ $MACOS ]
then
alias desktop="cd $HOME/Desktop"
fi
# android
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
# Cask
export PATH=$PATH:$HOME/.cask/bin
# Go
export GOPATH=$HOME/src/gobox
export PATH=$PATH:$GOPATH/bin
# Python
export PATH=$PATH:$HOME/Library/Python/2.7/bin/
# To fix libcurl errors from ETHO gem
# See https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
# nvm (Node Version Manager)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# pyenv (Python Version Manager)
export PYENV_ROOT="$HOME/.pyenv"
[ -d "$PYENV_ROOT/bin" ] && export PATH="$PYENV_ROOT/bin:$PATH"
if quiet_which pyenv; then
eval "$(pyenv init -)"
fi
# Lazy-load rbenv to speed up shell startup
if quiet_which rbenv; then
export PATH="$HOME/.rbenv/shims:$PATH"
rbenv() {
unset -f rbenv
eval "$(command rbenv init -)"
rbenv "$@"
}
fi
# Added by LM Studio CLI (lms) - only if directory exists
LMSTUDIO_PATH="$HOME/.lmstudio/bin"
[ -d "$LMSTUDIO_PATH" ] && export PATH="$PATH:$LMSTUDIO_PATH"
# End of LM Studio CLI section
genpasswd() {
local l=$1
[ "$l" == "" ] && l=16
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
# Save directory changes
cd() {
builtin cd "$@" || return
[ "$TERMINALAPP" ] && command -v set_terminal_app_pwd >/dev/null \
&& set_terminal_app_pwd
pwd > "$HOME/.lastpwd"
}
# To create shortcuts:
# mkdir $HOME/ss; cd $HOME/ss
# ln -s source shortcut
ss() {
cd "$HOME/ss/$@" &>/dev/null || echo "unknown shortcut"
}
function replace-string {
git grep -l "$1" | xargs sed -i '' -e"s/$1/$2/g"
}