-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_profile
164 lines (141 loc) · 5.93 KB
/
.bash_profile
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
#!/bin/bash
#
# .bash_profile
# this is run once for each login
# and contains environment variables
# that don't need to be redefined in child shells
#
# Cameron Blocker <[email protected]>
# Personal PATH extensions
export PATH=$HOME/bin:$HOME/.local/bin:$PATH
# Setup Editor config (PATH to subl needs to be set first)
# Use sublime text if available and not ssh, otherwise vim
if [ -z "$SSH_CLIENT" ] && [ -x "$(which subl)" ]; then
export EDITOR='subl -n -w '
else
if [ -x "$(which vim)" ]; then
export EDITOR='vim '
fi
fi
export GIT_EDITOR=$EDITOR
# a check that doesn't depend on the environment VVV
# SSH_IP=$(who am i | perl -ne '/.*\((.+)\)/ && print "$1";')
# Add colors to terminal
# for Mac
export CLICOLOR=1
export LSCOLORS=GxFxBxDxCxegedabagaced
# for Linux
# alias ls='ls --color'
# di-directory, fi-file, ln-symlink, pi-fifo, so-socket, bd-block, cd-character,
# or-orphan symlink, mi-non-existed file pointed to by orphan, ex-executable
export LS_COLORS='di=36:fi=0:ln=35:pi=31:so=31:bd=31:cd=31:or=47;35:mi=101:ex=32'
# 0 - white (files)
# 31 - red (i.e. this is abnormal)
# 32 - green (executables)
# 35 - purple (symlinks)
# 36 - cyan (directores)
# 5 - blinking (broken) but was annoying so...
# 101 - light red bg (broken)
# full list at http://linux-sxs.org/housekeeping/lscolors.html
# bold="\[\e[0;1m\]" moved to bashrc
# underline="\[\e[0;4m\]"
# invert="\[\e[0;7m\]"
# purple="\[\e[0;35m\]"
# cyan="\[\e[0;36m\]"
# reset="\[\e[0m\]"
# function _venv_info { # https://stackoverflow.com/a/30541526
# [[ -n "$VIRTUAL_ENV" ]] && echo "($purple${VIRTUAL_ENV##*/}$reset)"
# }
# Style Prompt (could go in bashrc since it depends on .git-prompt)
export GIT_PS1_SHOWCOLORHINTS=1
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUPSTREAM="auto"
export PROMPT_COMMAND='EXIT="$?";'${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}'__git_ps1 "$underline\!$reset[\h$(_screen_info):$cyan\W$reset]$(_venv_info)" "\$(if [ \$EXIT == 0 ]; then echo \"-> \" ; else echo \"\[\e[0;91m\]-> \[\e[0m\]\"; fi )"'
# export PS1='\!-[\h:\W]$(__git_ps1)->'
# PROMPT_COMMAND="__prompt_command" # Func to gen PS1 after CMDs
# __prompt_command() {
# local EXIT="$?" # This needs to be first
# PS1=""
# local RCol='\[\e[0m\]'
# local Red='\[\e[0;31m\]'
# local Gre='\[\e[0;32m\]'
# local BYel='\[\e[1;33m\]'
# local BBlu='\[\e[1;34m\]'
# local Pur='\[\e[0;35m\]'
# if [ $EXIT != 0 ]; then
# PS1+="${Red}\u${RCol}" # Add red if exit code non 0
# else
# PS1+="${Gre}\u${RCol}"
# fi
# PS1+="${RCol}@${BBlu}\h ${Pur}\W${BYel}$ ${RCol}"
# }
# Convenience Variable
export W=~/Workspace
##### The code below determines our dotfile dir. I would put it in its own
##### script in the dotfiles directory, but then I wouldn't be able to use
##### it to find where the dotfile directory is...
# copied from https://stackoverflow.com/questions/24112727/relative-paths-based-on-file-location-instead-of-current-working-directory
# it doesn't need to go in bashrc since we'll only use it once.
# Helper function.
rreadlink() ( # execute function in a *subshell* to localize the effect of `cd`, ...
local target=$1 fname targetDir readlinkexe=$(command -v readlink) CDPATH=
# Since we'll be using `command` below for a predictable execution
# environment, we make sure that it has its original meaning.
{ \unalias command; \unset -f command; } &>/dev/null
while :; do # Resolve potential symlinks until the ultimate target is found.
[[ -L $target || -e $target ]] || { command printf '%s\n' "$FUNCNAME: ERROR: '$target' does not exist." >&2; return 1; }
command cd "$(command dirname -- "$target")" # Change to target dir; necessary for correct resolution of target path.
fname=$(command basename -- "$target") # Extract filename.
[[ $fname == '/' ]] && fname='' # !! curiously, `basename /` returns '/'
if [[ -L $fname ]]; then
# Extract [next] target path, which is defined
# relative to the symlink's own directory.
if [[ -n $readlinkexe ]]; then # Use `readlink`.
target=$("$readlinkexe" -- "$fname")
else # `readlink` utility not available.
# Parse `ls -l` output, which, unfortunately, is the only POSIX-compliant
# way to determine a symlink's target. Hypothetically, this can break with
# filenames containig literal ' -> ' and embedded newlines.
target=$(command ls -l -- "$fname")
target=${target#* -> }
fi
continue # Resolve [next] symlink target.
fi
break # Ultimate target reached.
done
targetDir=$(command pwd -P) # Get canonical dir. path
# Output the ultimate target's canonical path.
# Note that we manually resolve paths ending in /. and /.. to make sure we
# have a normalized path.
if [[ $fname == '.' ]]; then
command printf '%s\n' "${targetDir%/}"
elif [[ $fname == '..' ]]; then
# Caveat: something like /var/.. will resolve to /private (assuming
# /var@ -> /private/var), i.e. the '..' is applied AFTER canonicalization.
command printf '%s\n' "$(command dirname -- "${targetDir}")"
else
command printf '%s\n' "${targetDir%/}/$fname"
fi
)
# Determine ultimate script dir. using the helper function.
# Note that the helper function returns a canonical path.
export dotfileDir=$(dirname -- "$(rreadlink "$BASH_SOURCE")")
### This goes last so it can use the above environment
# -e for exist instead of -f for regular file since it can be symlink
if [ -e ~/.bashrc ]; then
source ~/.bashrc
fi
if [ -x "$(which hostname)" ]; then
case "$(hostname -s)" in
Marvin)
# source specific paths and vars for Marvin (macOS laptop)
source $dotfileDir/marvin.bash_profile
;;
ir*)
# source specific paths and vars for ir research machines
#echo "hello ir"
source $dotfileDir/ir.bash_profile
;;
esac
fi
### End .bash_profile ### (anything below this was auto appended)