-
Notifications
You must be signed in to change notification settings - Fork 1
/
bashrc
155 lines (121 loc) · 3.29 KB
/
bashrc
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
# If not running interactively, don't do anything.
[ -z "$PS1" ] && return
if [ -z "$user_bashrc_already_run" ]; then
user_bashrc_already_run=1
else
return
fi
# => Constants ------------------------------------------------------------ {{{1
if [ `uname` == "Darwin" ]; then
export IS_MAC=1
else
export IS_MAC=0
fi
# => Includes ------------------------------------------------------------- {{{1
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
if [ -f ~/.git_prompt.sh ]; then
. ~/.git_prompt.sh
fi
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# Google-specific .bashrc.
if [ -f ~/.bashrc.google ]; then
. ~/.bashrc.google
fi
# => Environment configuration -------------------------------------------- {{{1
# History settings.
HISTCONTROL=ignoredups:ignorespace
HISTSIZE=1000000
HISTFILESIZE=2000000
# Write history after every command.
export PROMPT_COMMAND='history -a'
# Shell opts.
shopt -s histappend
shopt -s checkwinsize
# More colors in a terminal.
export TERM=xterm-256color
# More color if running tmux.
[ -n "$TMUX" ] && export TERM=screen-256color
# Text editor.
export EDITOR=vim
# Put ~/bin on PATH if it exists.
test -d "$HOME/bin" && PATH="$HOME/bin:$PATH"
# => Prompt --------------------------------------------------------------- {{{1
PS1='\w$ '
# => Include local config ------------------------------------------------- {{{1
if [ -f ~/.bashrc.local ]; then
. ~/.bashrc.local
fi
# => Apparix -------------------------------------------------------------- {{{1
function to () {
if test "$2"; then
cd "$(apparix "$1" "$2" || echo .)";
else
cd "$(apparix "$1" || echo .)";
fi
pwd
}
function bm () {
if test "$2"; then
apparix --add-mark "$1" "$2";
elif test "$1"; then
apparix --add-mark "$1";
else
apparix --add-mark;
fi
}
function portal () {
if test "$1"; then
apparix --add-portal "$1";
else
apparix --add-portal;
fi
}
function _apparix_aliases ()
{ cur=$2
dir=$3
COMPREPLY=()
if [ "$1" == "$3" ]
then
COMPREPLY=( $( cat $HOME/.apparix{rc,expand} | \
grep "j,.*$cur.*," | cut -f2 -d, ) )
else
dir=`apparix -favour rOl $dir 2>/dev/null` || return 0
eval_compreply="COMPREPLY=( $(
cd "$dir"
\ls -d *$cur* | while read r
do
[[ -d "$r" ]] &&
[[ $r == *$cur* ]] &&
echo \"${r// /\\ }\"
done
) )"
eval $eval_compreply
fi
return 0
}
alias als="apparix"
complete -F _apparix_aliases to
# => Ranger ---------------------------------------------------------------- {{{1
function ranger-cd {
tempfile="$(mktemp -t tmp.XXXXXX)"
/usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}"
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
cd -- "$(cat "$tempfile")"
fi
rm -f -- "$tempfile"
}
# This binds Ctrl-O to ranger-cd:
bind '"\C-o":"ranger-cd\C-m"'
# => Misc ----------------------------------------------------------------- {{{1
# Fuzzy file autocomplete.
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# Colorized less output.
export LESS='-R'
export LESSOPEN='|~/bin/lessfilter %s'
# Allow Vim to use xclipboard during SSH/tmux sessions.
export DISPLAY=:0.0