-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
133 lines (113 loc) · 2.95 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
# General Bash
##############
# history
export HISTCONTROL=ignoreboth
export HISTSIZE=10000
export HISTFILESIZE=5000
shopt -s histappend
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
# vi bindings
set -o vi
bind -m vi-command ".":insert-last-argument
bind -m vi-insert "\C-l.":clear-screen
bind -m vi-insert "\C-a.":beginning-of-line
bind -m vi-insert "\C-e.":end-of-line
# set defaults
export EDITOR="/usr/bin/vim"
export VISUAL="/usr/bin/vim"
export PAGER="/usr/bin/less"
export LESS="-R" # for color
# aliases
if [[ -f ~/.bash_aliases ]]; then
source ~/.bash_aliases
fi
# custom for machine. this useful for things that are specific to work
if [[ -f ~/.bash_custom ]]; then
source ~/.bash_custom
fi
# prompt for git/hg because that is what I use
if [[ -f ~/.scm_prompt ]]; then
source ~/.scm_prompt
else
export PS1='[\w]\$ '
fi
# Renv because I love R
if [[ -d $HOME/.Renv ]]; then
export PATH="$HOME/.Renv/bin:$PATH"
eval "$(Renv init -)"
fi
# Functions
###########
# make a directory appended with the date
mkdirdate() {
if [ -z "$1" ]; then
echo "Please specify a directory name"
return
fi
DIR_NAME=$(date +'%Y-%m-%d')-"$1"
mkdir ${DIR_NAME}
cd ${DIR_NAME}
}
# make a directory and cd into it
mkdircd() {
DIR_NAME="$1"
mkdir -p ${DIR_NAME}
cd ${DIR_NAME}
}
# cd into the git root or noop
gr() {
ROOT_DIR=$(git root)
cd ${ROOT_DIR:-.}
}
# cd into the hg root or noop
hr() {
ROOT_DIR=$(hg root)
cd ${ROOT_DIR:-.}
}
# move the last downloaded file to a destination or the current dir
mvlastdl() {
SEARCH_DIR="${HOME}/Downloads"
MV_DIR=${1:-.}
LAST_FILE="$(ls -t ${SEARCH_DIR} | head -1)"
if [[ ${LAST_FILE} == *download ]]; then
echo "File is still downloading, wait a bit"
else
echo "Moving" ${SEARCH_DIR}/${LAST_FILE} "to" ${MV_DIR}
mv -- "${SEARCH_DIR}/${LAST_FILE}" ${MV_DIR}
fi
}
# change the directory to the last modified one
cdlm() {
LAST_MOD_DIR=$(ls -rd */ 2> /dev/null | head -1)
cd ${LAST_MOD_DIR:-.}
}
# try a couple third-party packages for printing source files with color
color_cat() {
if $(command -v highlight > /dev/null 2>&1); then
highlight -O ansi "$1" 2> /dev/null || cat "$1"
elif $(command -v pygmentize > /dev/null 2>&1); then
pygmentize -g "$1" 2> /dev/null || cat "$1"
else
cat "$1"
fi
}
# override any ccat functions in the path
alias ccat='color_cat '
# Prevents me from accidentally doing `pkill .`
# which is very, very annoying
pkill() {
for i in $@; do :; done # get last argument
if [[ "$i" == "." ]]; then
echo "I'm sorry, Dave. I'm afraid I can't do that."
else
pkill "$@"
fi
}
# Platform Specific
###################
UNAME=$(uname)
LINUX="Linux"
# if on linux, switch caps with escape
if [[ ${UNAME} = ${LINUX} && $(command -v xmodmap > /dev/null 2>&1) ]]; then
xmodmap ~/.speedswapper
fi