cbc1d0552df9f7ce5ebbba34bb8b9b62c8b520bf
David Blume Fixed when /etc bashrc gets...

David Blume authored 8 years ago

1) if [[ $(uname -s) != Darwin* ]] && [ -f /etc/bashrc ]; then
2)     # Fedora but not Macintosh requires explicit sourcing of /etc/bashrc
3)     # On Debian, it's /etc/bash.bashrc, but it doesn't have to be sourced here.
4)     . /etc/bashrc
5) fi
6) 
dblume Make local __git_ps1 work a...

dblume authored 2 years ago

7) if ! $(declare -F __git_ps1 >/dev/null); then
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

8)     # Try to source a file with __git_ps1
9)     if [[ -e /usr/lib/git-core/git-sh-prompt ]]; then
dblume Try to source a script for...

dblume authored 2 years ago

10)         . /usr/lib/git-core/git-sh-prompt
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

11)     elif [[ -e /usr/share/git-core/contrib/completion/git-prompt.sh ]]; then
dblume Try to source a script for...

dblume authored 2 years ago

12)         . /usr/share/git-core/contrib/completion/git-prompt.sh
13)     elif [[ $(uname -s) == Darwin* ]] && [[ -f $(brew --prefix git)/etc/bash_completion.d/git-prompt.sh ]]; then
14)         . $(brew --prefix git)/etc/bash_completion.d/git-prompt.sh
dblume Add option to manually down...

dblume authored 2 years ago

15)     elif [[ -f $HOME/.git-prompt.sh ]]; then
16)         # wget -O ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
17)         . $HOME/.git-prompt.sh
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

18)     fi
19) 
20)     # Still no __git_ps1? Fake it.
21)     if ! $(declare -F __git_ps1 >/dev/null); then
dblume Don't call git if not in a...

dblume authored 2 years ago

22)         # By icetan at https://stackoverflow.com/a/35513635/9181
23)         # Ex. to test if in a git repo: "rtrav .git $PWD"
24)         rtrav() { [ -e "$2"/"$1" ] || { [ "$2" != / ] && rtrav "$1" $(dirname "$2"); } }
25) 
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

26)         __git_ps1() {
dblume Don't call git if not in a...

dblume authored 2 years ago

27)             if rtrav .git "$PWD"; then
28)                 local fmt="${1:- (%s)}"
29)                 local branch=$(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
30)                 if [ -n "$branch" ]; then
31)                     printf -- "$fmt" "$branch"
32)                 fi
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

33)             fi
34)         }
35)     fi
dblume Use __git_ps1 when possible.

dblume authored 2 years ago

36) fi
dblume Experiment: Add git branch...

dblume authored 2 years ago

37) 
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

38) GIT_PS1_SHOWUPSTREAM="auto"
39) GIT_PS1_SHOWDIRTYSTATE="true"
dblume Don't call git if not in a...

dblume authored 2 years ago

40) GIT_PS1_STATESEPARATOR=""
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

41) 
42) # Experimenting with git branch in PS1. Turn off by setting to false.
dblume Experiment: Add git branch...

dblume authored 2 years ago

43) if true ; then
dblume Shorten directory in prompt...

dblume authored 2 years ago

44)     export PROMPT_DIRTRIM=1
dblume Experiment: Add git branch...

dblume authored 2 years ago

45)     # I like 023 or 030 for the git branch color. See https://i.stack.imgur.com/UQVe5.png
46)     if [[ -n $SSH_CLIENT ]]; then
47)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

48)                       else echo -e "\[\e[31m\]\xe2\x9c\x97"; fi) \[\e[38;5;242m\]\h:\w$(__git_ps1 " \[\e[38;5;030m\]%s\[\e[38;5;242m\]")$\[\e[0m\] '
dblume Experiment: Add git branch...

dblume authored 2 years ago

49)     else
50)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

51)                       else echo -e "\[\e[31m\]\xe2\x9c\x97"; fi) \[\e[38;5;242m\]\w$(__git_ps1 " \[\e[38;5;030m\]%s\[\e[38;5;242m\]")$\[\e[0m\] '
dblume Experiment: Add git branch...

dblume authored 2 years ago

52)     fi
David Blume New PS1 with error detectio...

David Blume authored 6 years ago

53) else
dblume Shorten directory in prompt...

dblume authored 2 years ago

54)     export PROMPT_DIRTRIM=4
dblume Experiment: Add git branch...

dblume authored 2 years ago

55)     if [[ -n $SSH_CLIENT ]]; then
56)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
57)                       else echo -e "\[\e[31m\]\xe2\x9c\x97"; fi) \[\e[38;5;242m\]\h:\w$\[\e[0m\] '
58)     else
59)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
60)                       else echo -e "\[\e[31m\]\xe2\x9c\x97"; fi) \[\e[38;5;242m\]\w$\[\e[0m\] '
61)     fi
David Blume New PS1 with error detectio...

David Blume authored 6 years ago

62) fi
63) 
64) set -o vi
David Blume first commit

David Blume authored 8 years ago

65) 
66) add_to_path() {
67)     if [ -d "$1" ] && [[ ! $PATH =~ (^|:)$1(:|$) ]]; then
68)         PATH+=:$1
69)     fi
70) }
71) 
72) # if this is a CygWin .bashrc, then set CygWin's commands first in PATH
73) # because link.exe and find.exe exist in Windows's path.
74) # Add /usr/lib/lapack at the end so python's numpy can find lapack_lite
75) # (Note: BSD bash, used by OS X doesn't have the "substr" test for expr.)
76) if [[ $(uname -s) == CYGWIN* ]]; then
David Blume Use spaces instead of tabs.

David Blume authored 8 years ago

77)     PATH=/usr/local/bin:/usr/bin:$PATH
78)     PATH=${PATH//":/usr/local/bin:/usr/bin"/} # delete any instances in middle
79)     add_to_path /usr/lib/lapack
David Blume Add md() support for Cygwin...

David Blume authored 5 years ago

80)     export GIT_SSH=/cygdrive/c/cygwin64/bin/ssh
David Blume Use spaces instead of tabs.

David Blume authored 8 years ago

81)     ulimit -n 1024 # for "duplicity"
David Blume Add support for 'md' on WSL.

David Blume authored 4 years ago

82) elif [[ -n "${WSL_DISTRO_NAME}" ]]; then
83)     export BROWSER=/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe
David Blume first commit

David Blume authored 8 years ago

84) fi
85) 
David Blume whitespace

David Blume authored 6 years ago

86) # change the color of directories in the ls command
David Blume Refactor .bashrc to keep di...

David Blume authored 8 years ago

87) if [[ $(uname -s) == Darwin* ]]; then
88)     export LSCOLORS=gxfxcxdxbxegedabagacad
89)     export CLICOLOR=1
90) else
91)     # After executing: dircolors -p > .dircolors
92)     # Lighten the color of directories from blue to light blue
93)     # sed -i '/# directory/c\DIR 00;36 # directory' .dircolors
94)     if [ -x /usr/bin/dircolors ]; then
95)         test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
96)         alias ls='ls --color=auto'
97)     fi
David Blume first commit

David Blume authored 8 years ago

98) fi
99) 
David Blume Add .vimrc tab values for ....

David Blume authored 7 years ago

100) export P4DIFF='vim -d'  # Override from the command line: "P4DIFF=; p4 diff main.py"
David Blume Set vim as editor for cscope

David Blume authored 6 years ago

101) export CSCOPE_EDITOR=vim
David Blume Add .vimrc tab values for ....

David Blume authored 7 years ago

102) 
David Blume Add alias for colors in ls...

David Blume authored 8 years ago

103) alias grep='grep --color=auto'
104) alias fgrep='fgrep --color=auto'
105) alias egrep='egrep --color=auto'
David Blume I almost always want to do...

David Blume authored 4 years ago

106) alias vim-='vim +"setl buftype=nofile" -'
dblume vim: Use more common char f...

dblume authored 2 years ago

107) alias tmux='tmux -2u'
David Blume Add alias for colors in ls...

David Blume authored 8 years ago

108) 
109) # colored GCC warnings and errors
110) export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
111) 
David Blume first commit

David Blume authored 8 years ago

112) # Add to PATH only if not already in PATH.
113) add_to_path $HOME/bin
114) 
David Blume disable ctrl+s as stty flow...

David Blume authored 3 years ago

115) # For interactive shells ('i' in $-), disable stty flow control (ctrl+s,ctrl+q)
116) case "$-" in
117) *i*)
118)   stty start ''
119)   stty stop  ''
120)   stty -ixon # disable XON/XOFF flow control
121)   stty ixoff # enable sending (to app) of start/stop characters
122)   stty ixany # let any character restart output, not only start character
123)   ;;
124) *) ;;
125) esac
126) 
David Blume first commit

David Blume authored 8 years ago

127) alias findinpyfiles="find . -name \*.py -print0 | xargs -0 grep -nI"
David Blume Add a few c++ aliases, and...

David Blume authored 8 years ago

128) alias findinchppfiles="find . -type f \( -name \*.[ch]pp -or -name \*.[ch] \) -print0 | xargs -0 grep -nI"
129) alias findincppfiles="find . -type f \( -name \*.cpp -or -name \*.c \) -print0 | xargs -0 grep -nI"
130) alias findinhppfiles="find . -type f \( -name \*.hpp -or -name \*.h \) -print0 | xargs -0 grep -nI"
131) 
132) alias clip="expand | cut -b1-\$COLUMNS"
David Blume Optionally source a .localr...

David Blume authored 7 years ago

133) 
David Blume Add alias for httpie https

David Blume authored 6 years ago

134) # For httpie: https://github.com/jakubroztocil/httpie#installation
135) alias https='http --default-scheme=https'
136) 
David Blume Add a command for viewing M...

David Blume authored 5 years ago

137) md() {
David Blume Make the local variables co...

David Blume authored 5 years ago

138)     declare -r sys_name=$(uname -s)
David Blume Add md() support for Cygwin...

David Blume authored 5 years ago

139)     if [[ $sys_name == Darwin* ]]; then
David Blume Make the local variables co...

David Blume authored 5 years ago

140)         declare -r T=$(mktemp $TMPDIR$(uuidgen).html)
David Blume Add md() support for Cygwin...

David Blume authored 5 years ago

141)         curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
David Blume No need to specify Safari t...

David Blume authored 5 years ago

142)         open $T
David Blume Add md() support for Cygwin...

David Blume authored 5 years ago

143)     elif [[ $sys_name == CYGWIN* ]]; then
David Blume Make the local variables co...

David Blume authored 5 years ago

144)         declare -r T=$(mktemp --suffix=.html)
David Blume Add md() support for Cygwin...

David Blume authored 5 years ago

145)         curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
146)         cygstart $T
David Blume Add a command for viewing M...

David Blume authored 5 years ago

147)     else
David Blume Make the local variables co...

David Blume authored 5 years ago

148)         declare -r T=$(mktemp --suffix=.html)
David Blume Add md() support for Cygwin...

David Blume authored 5 years ago

149)         curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
David Blume Add support for 'md' on WSL.

David Blume authored 4 years ago

150)         if [[ -z "${WSL_DISTRO_NAME}" ]]; then
151)             xdg-open $T
152)             echo "rm \"$T\" >/dev/null 2>&1" | at now + 2 minutes
153)         else
154)             # Set BROWSER to your web browser's path
dblume Don't call git if not in a...

dblume authored 2 years ago

155)             "$BROWSER" '\\wsl$/Ubuntu'$T
David Blume Add support for 'md' on WSL.

David Blume authored 4 years ago

156)         fi
David Blume Add a command for viewing M...

David Blume authored 5 years ago

157)     fi
158) }
159) 
David Blume I almost always want to do...

David Blume authored 4 years ago

160) concept() {
David Blume Add support for tmux; use p...

David Blume authored 4 years ago

161)     # apropos -s 7 . | awk '!/iso|latin/ {print $1}' | shuf -n 1 | xargs man 7
162)     apropos -s 7 . | awk '!/iso|latin/ {print $1}' | shuf -n 1 | pee "xargs echo man 7" "xargs man 7"
David Blume I almost always want to do...

David Blume authored 4 years ago

163) }
164) 
David Blume Added venv command

David Blume authored 3 years ago

165) venv() {
David Blume venv() supports filename co...

David Blume authored 3 years ago

166)     # Inspired by https://twitter.com/gvanrossum/status/1319328122618048514
167)     if hash deactivate 2>/dev/null; then
168)         deactivate
169)     fi
170)     if [[ $1 ]]; then
171)         if [ ! -f $1/bin/activate ]; then
172)             echo "Creating with: python3 -m venv $1"
173)             python3 -m venv $1
David Blume Added venv command

David Blume authored 3 years ago

174)         fi
David Blume venv() supports filename co...

David Blume authored 3 years ago

175)         source $1/bin/activate
David Blume Added venv command

David Blume authored 3 years ago

176)     fi
177) }
178) 
David Blume Moving ignoredups:erasedups...

David Blume authored 5 years ago

179) # https://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows
180) HISTCONTROL=ignoredups:erasedups
David Blume Add some commands to exclud...

David Blume authored 5 years ago

181) HISTIGNORE="&:ls:[bf]g:exit:pwd:clear"
David Blume I almost always want to do...

David Blume authored 4 years ago

182) #HISTFILESIZE=2000
183) #HISTSIZE=2000
184) # [ $(wc -l < $HOME/.bash_history) -gt 950 ] && echo "David, your .bash_history is over 950 lines. Consider updating your .bashrc."
David Blume Moving ignoredups:erasedups...

David Blume authored 5 years ago

185) shopt -s histappend
186) 
David Blume Forgot a corresponding chan...

David Blume authored 7 years ago

187) if [ -f $HOME/.localrc ]; then
David Blume Specify path for .localrc

David Blume authored 7 years ago

188)     source $HOME/.localrc