-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc_portable
178 lines (154 loc) · 5.26 KB
/
.bashrc_portable
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
#include this file in .bashrc like this:
#if [ -f ~/.bashrc_portable ]; then
# . ~/.bashrc_portable
#else
# echo -e "\t (no .bashrc_portable file found)"
#fi
if [ -f .bash_aliases ]; then
. .config/aliases
fi
alias vlf="vi $(\ls -t | head -n1)" #open the file with the newest timestamp in the directory
#system specific aliases
uname=$(uname -a)
if [[ $uname =~ ^Linux ]]; then
echo "detected linux"
alias ls="\ls -la --color=auto"
alias ll="\ls -l --color=auto"
elif [[ $uname =~ ^Darwin ]]; then
echo "detected darwin"
alias ls="\ls -la -G"
alias ll="\ls -l -G"
else
echo "could not detect operating system"
fi
function c {
#color table swiped from http://tammersaleh.com/posts/a-better-rvm-bash-prompt/
# regular colors
case $1 in
# colors
K) echo "\[\033[0;30m\]" ;;
R) echo "\[\033[0;31m\]" ;;
G) echo "\[\033[0;32m\]" ;;
Y) echo "\[\033[0;33m\]" ;;
B) echo "\[\033[0;34m\]" ;;
M) echo "\[\033[0;35m\]" ;;
C) echo "\[\033[0;36m\]" ;;
W) echo "\[\033[0;37m\]" ;;
# emphasized (bolded) colors
EMK) echo "\[\033[1;30m\]" ;;
EMR) echo "\[\033[1;31m\]" ;;
EMG) echo "\[\033[1;32m\]" ;;
EMY) echo "\[\033[1;33m\]" ;;
EMB) echo "\[\033[1;34m\]" ;;
EMM) echo "\[\033[1;35m\]" ;;
EMC) echo "\[\033[1;36m\]" ;;
EMW) echo "\[\033[1;37m\]" ;;
# background colors
BGK) echo "\[\033[40m\]" ;;
BGR) echo "\[\033[41m\]" ;;
BGG) echo "\[\033[42m\]" ;;
BGY) echo "\[\033[43m\]" ;;
BGB) echo "\[\033[44m\]" ;;
BGM) echo "\[\033[45m\]" ;;
BGC) echo "\[\033[46m\]" ;;
BGW) echo "\[\033[47m\]" ;;
# not-colors
*) echo "\[\033[0m\]" ;;
esac
}
function _git_bang_if_dirty { # http://tammersaleh.com/posts/a-better-rvm-bash-prompt/
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo "!"
}
function _git_dash_unless_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] || echo "-"
}
function _git_current_branch { # adapted from http://amix.dk/blog/post/19571
git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function _git_hash { # thank you mr. seguin
sha=($(git log -1 2>/dev/null)) # parens make it an array, space seperated
sha=${sha[1]} # pull out the full hash
echo ${sha:0:7} # first few characters of the hash
}
cs () { cd "$1" && ls; } #cd then ls
#PS1='\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1=""
#PS1="$PS1\n" # newline
PS1="$PS1$(c EMR)\$(_git_bang_if_dirty)$(c)" # exclamation point if branch is dirty
PS1="$PS1$(c C)\$(_git_current_branch)$(c)" # current branch name
PS1="$PS1$(c K)@\$(_git_hash)$(c)" # current sha hash
PS1="$PS1$(c K) \D{%b-%d %H:%m:%S}$(c)" # time, so we can see when the last command finished, black, so its there when we need it but not in the way.
PS1="$PS1\n" # newline
PS1="$PS1$(c G)\u@\h$(c):$(c B)\w$(c)\$ " # the real prompt
screen -x
##################################################################################
#
# Open a file in a vim session, use sudo if needed.
#
vib() {
if test -w $1; then
vim $1
else
sudo vim $1
fi
}
#
# For use when resuming remote screen session to re-sync
# ssh agent, and thus keys push through the new ssh session
# and make them available to shells running inside of screen
#
# Run before connecting to screen to dump env vars to a file,
# then resume or extend screen session and run again to
# import those env vars to the current environment.
#
keyme() {
if [[ $TERM =~ "screen" ]]; then
echo -n "Importing ssh agent - "
if [ -s $HOME/.ssh/envs ]; then
. $HOME/.ssh/envs
echo "Success!"
else
echo "No envs file found."
fi
else
echo -n "Exporting ssh agent - "
# Courtesy of http://www.deadman.org/sshscreen.php
SSHVARS="SSH_CLIENT SSH_TTY SSH_AUTH_SOCK SSH_CONNECTION DISPLAY"
for x in ${SSHVARS} ; do
(eval echo $x=\$$x) | sed 's/=/="/
s/$/"/
s/^/export /'
done 1>$HOME/.ssh/envs
echo "Success!"
fi
}
# OSX: Run a command in a new terminal tab -- probably will blow up or something on nix's
# shamelessly nabbed from http://tomafro.net/2009/08/tip-open-new-tab-in-osx-terminal
tab () {
osascript 2>/dev/null <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
end
tell application "Terminal"
activate
do script with command "cd $PWD; $*" in window 1
end tell
EOF
}
#
# Start up the rails dev environment in the current directory, again probably blows up on nix's
#
# Might be worth it to write some logic that encapsulates screen/osx commands into generics...
#
workflow () {
tab rc # start rails console in a new tab
[[ -f Guardfile ]] && tab guard # start guard in a new tab
tab # blank tab for rake tasks and such
mvim . &>/dev/null # open up macvim in this directory -- auto-opens tabs for relevant rails folders
rs # start the rails server in this tab
}
notes () {
[[ -f ~/notes.md ]] && less ~/notes.md
}