-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc_remote
185 lines (157 loc) · 5.62 KB
/
.bashrc_remote
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
#===============================================================================
# This is for use on servers where I can't add my own config files, so it's much
# more limited than my full dotfiles - just the things I'm likely to use on
# other people's servers.
#
# It is read by 'ssh-with-bashrc' and passed via SSH, so it can't be too long.
# The maximum length of a command + environment variables is around 2MB on
# Ubuntu (according to `getconf ARG_MAX`), which should be plenty. I tried
# passing it over FD3 instead, but SSH doesn't pass additional file descriptors
# to the remote server.
#
# Comments and blank lines are removed before sending.
#===============================================================================
# Read the standard config files, because --rcfile disables them
[[ -f /etc/profile ]] && source /etc/profile
[[ -f /etc/bash.bashrc ]] && source /etc/bash.bashrc
[[ -f ~/.profile ]] && source ~/.profile
[[ -f ~/.bashrc ]] && source ~/.bashrc
# Just in case - don't override dotfiles config
[[ -d ~/.dotfiles ]] && return
# Escape hatch - reload Bash without this config
# I tried using 'env -i', but it removes too much (e.g. $TERM)
alias reload='exec env \
-u EDITOR \
-u GREP_COLORS \
-u LESS \
-u LS_COLORS \
-u GIT_AUTHOR_NAME \
-u GIT_AUTHOR_EMAIL \
-u GIT_COMMITTER_NAME \
-u GIT_COMMITTER_EMAIL \
bash -l'
# Shortcuts I use regularly (simplified versions in many cases)
c() {
if cd "$@"; then
echo -en "\n\e[97;1;4m"
echo -n "$PWD"
echo -e "\e[0m"
timeout 1 ls --color=always -hFld *
fi
}
e() {
vim \
-c 'colorscheme torte' \
-c 'set confirm' \
-c 'nmap <silent> ,q :q<CR>' \
-c 'noremap <silent> <C-S> :wall<CR>' \
-c 'vnoremap <silent> <C-S> <C-C>:wall<CR>' \
-c 'inoremap <silent> <C-S> <Esc>:wall<CR>gi' \
-c 'nnoremap ; :' \
-c 'vnoremap ; :' \
"$@"
}
g() {
case "${1-}" in
co) shift; git checkout "$@" ;;
d) shift; git diff "$@" ;;
f) shift; git fetch "$@" ;;
io) shift; git log --left-right --cherry-pick "${1-$(git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)")}...${2-HEAD}" ;;
l) shift; git log "$@" ;;
pl) shift; git pull "$@" ;;
s) shift; git status "$@" ;;
*) git "$@" ;;
esac
}
alias com='composer'
alias cw='c /local'
alias l="ls --color=always -hFl"
alias sc='systemctl'
# Shortcut to upgrade to full dotfiles install
setup-dotfiles() {
wget djm.me/dot -O ~/dot
cd
. dot
unset -f setup-dotfiles
}
# Better tab completion + history searching (see .inputrc)
bind 'set colored-completion-prefix on'
bind 'set colored-stats on'
bind 'set completion-ignore-case on'
bind 'set completion-map-case on'
bind 'set mark-symlinked-directories on'
bind 'set match-hidden-files off'
bind 'set menu-complete-display-prefix on'
bind 'set page-completions off'
bind 'set revert-all-at-newline on'
bind 'set show-all-if-ambiguous on'
bind 'set show-all-if-unmodified on'
bind 'set visible-stats on'
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind 'Tab: menu-complete'
bind '"\e[Z": menu-complete-backward'
# Navigation via keyboard shortcuts (see .bashrc for explanations)
dirhistory_past=()
dirhistory_future=()
_dirhistory-push-future() {
if [[ ${#dirhistory_future[@]} -eq 0 || ${dirhistory_future[0]} != "$1" ]]; then
dirhistory_future=("$1" "${dirhistory_future[@]:0:49}")
fi
}
_dirhistory-push-past() {
if [[ ${#dirhistory_past[@]} -eq 0 || ${dirhistory_past[0]} != "$1" ]]; then
dirhistory_past=("$1" "${dirhistory_past[@]:0:49}")
fi
}
nextd() {
local dir=$PWD
while [[ ${dirhistory_future[0]} == $dir ]]; do
dirhistory_future=("${dirhistory_future[@]:1}")
done
if [[ ${#dirhistory_future[@]} -gt 0 ]]; then
if builtin cd "${dirhistory_future[0]}"; then
_dirhistory-push-past "$dir"
fi
fi
}
prevd() {
local dir=$PWD
while [[ ${dirhistory_past[0]} == $dir ]]; do
dirhistory_past=("${dirhistory_past[@]:1}")
done
if [[ ${#dirhistory_past[@]} -gt 0 ]]; then
if builtin cd "${dirhistory_past[0]}"; then
_dirhistory-push-future "$dir"
fi
fi
}
cd() {
local dir=$PWD
builtin cd "$@" && _dirhistory-push-past "$dir"
}
_dirhistory-push-past "$PWD"
bind -x '"\200": TEMP_LINE=$READLINE_LINE; TEMP_POINT=$READLINE_POINT'
bind -x '"\201": READLINE_LINE=$TEMP_LINE; READLINE_POINT=$TEMP_POINT; unset TEMP_POINT; unset TEMP_LINE'
bind '"\e[1;7D": "\200\C-a\C-kprevd\C-m\201"'
bind '"\e[1;7C": "\200\C-a\C-knextd\C-m\201"'
bind '"\e[1;7A": "\200\C-a\C-kc ..\C-m\201"'
bind '"\e[1;7B": "\C-a\C-kc \e[Z"'
# Better prompt (simplified version of what's in .bashrc)
PS1='\e]2;$USER@\h\a\n\e[37;100m$(printf "%-${COLUMNS}s" " No Dotfiles")\e[0m\n\e[90m[\e[91m$USER\e[90m@\e[92m$HOSTNAME\e[90m:\e[93m$PWD\e[90m at \e[37m$(date +%H:%M:%S)\e[90m]\e[0m\n\[\e[91m\]$\[\e[0m\] '
# Configure other applications (same as in .bash_profile)
export LESS='FRX'
export GREP_COLORS='ms=91:mc=91:sl=:cx=:fn=35:ln=32:bn=32:se=36'
export LS_COLORS='rs=0:fi=97:di=93:ln=96:mh=00:pi=40;33:so=95:do=95:bd=40;93:cd=40;93:or=40;91:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=92'
export EDITOR='vim'
export VISUAL='vim'
# Git config (placeholders replaced in 'ssh-with-bashrc')
export GIT_AUTHOR_NAME='__GIT_NAME__'
export GIT_AUTHOR_EMAIL='__GIT_EMAIL__'
export GIT_COMMITTER_NAME='__GIT_NAME__'
export GIT_COMMITTER_EMAIL='__GIT_EMAIL__'
# Display directory listing
c .
# Uncomment these to test escaping
#echo "Test 1 ' OK"
#echo 'Test 2 " OK'