d1682419bb273b01e079b9d445d36b68dddff66c
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
10)             . /usr/lib/git-core/git-sh-prompt
11)     elif [[ -e /usr/share/git-core/contrib/completion/git-prompt.sh ]]; then
12)             . /usr/share/git-core/contrib/completion/git-prompt.sh
13)     fi
14) 
15)     # Still no __git_ps1? Fake it.
16)     if ! $(declare -F __git_ps1 >/dev/null); then
17)         __git_ps1() {
18)             local fmt="${1:- (%s)}"
19)             local branch=$(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
20)             if [ -n "$branch" ]; then
21)                 printf "$fmt" "$branch"
22)             fi
23)         }
24)     fi
dblume Use __git_ps1 when possible.

dblume authored 2 years ago

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

dblume authored 2 years ago

26) 
dblume Try to source __git_ps1 fir...

dblume authored 2 years ago

27) GIT_PS1_SHOWUPSTREAM="auto"
28) GIT_PS1_SHOWDIRTYSTATE="true"
29) 
30) # Experimenting with git branch in PS1. Turn off by setting to false.
dblume Experiment: Add git branch...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

33)     # I like 023 or 030 for the git branch color. See https://i.stack.imgur.com/UQVe5.png
34)     if [[ -n $SSH_CLIENT ]]; then
35)         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

36)                       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

37)     else
38)         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

39)                       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

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

David Blume authored 6 years ago

41) else
dblume Shorten directory in prompt...

dblume authored 2 years ago

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

dblume authored 2 years ago

43)     if [[ -n $SSH_CLIENT ]]; then
44)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
45)                       else echo -e "\[\e[31m\]\xe2\x9c\x97"; fi) \[\e[38;5;242m\]\h:\w$\[\e[0m\] '
46)     else
47)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
48)                       else echo -e "\[\e[31m\]\xe2\x9c\x97"; fi) \[\e[38;5;242m\]\w$\[\e[0m\] '
49)     fi
David Blume New PS1 with error detectio...

David Blume authored 6 years ago

50) fi
51) 
52) set -o vi
David Blume first commit

David Blume authored 8 years ago

53) 
54) add_to_path() {
55)     if [ -d "$1" ] && [[ ! $PATH =~ (^|:)$1(:|$) ]]; then
56)         PATH+=:$1
57)     fi
58) }
59) 
60) # if this is a CygWin .bashrc, then set CygWin's commands first in PATH
61) # because link.exe and find.exe exist in Windows's path.
62) # Add /usr/lib/lapack at the end so python's numpy can find lapack_lite
63) # (Note: BSD bash, used by OS X doesn't have the "substr" test for expr.)
64) if [[ $(uname -s) == CYGWIN* ]]; then
David Blume Use spaces instead of tabs.

David Blume authored 8 years ago

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

David Blume authored 5 years ago

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

David Blume authored 8 years ago

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

David Blume authored 4 years ago

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

David Blume authored 8 years ago

72) fi
73) 
David Blume whitespace

David Blume authored 6 years ago

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

David Blume authored 8 years ago

75) if [[ $(uname -s) == Darwin* ]]; then
76)     export LSCOLORS=gxfxcxdxbxegedabagacad
77)     export CLICOLOR=1
78) else
79)     # After executing: dircolors -p > .dircolors
80)     # Lighten the color of directories from blue to light blue
81)     # sed -i '/# directory/c\DIR 00;36 # directory' .dircolors
82)     if [ -x /usr/bin/dircolors ]; then
83)         test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
84)         alias ls='ls --color=auto'
85)     fi
David Blume first commit

David Blume authored 8 years ago

86) fi
87) 
David Blume Add .vimrc tab values for ....

David Blume authored 8 years ago

88) 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

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

91) alias grep='grep --color=auto'
92) alias fgrep='fgrep --color=auto'
93) alias egrep='egrep --color=auto'
David Blume I almost always want to do...

David Blume authored 4 years ago

94) alias vim-='vim +"setl buftype=nofile" -'
David Blume Add support for tmux; use p...

David Blume authored 4 years ago

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

David Blume authored 8 years ago

96) 
97) # colored GCC warnings and errors
98) export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
99) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 3 years ago

103) # For interactive shells ('i' in $-), disable stty flow control (ctrl+s,ctrl+q)
104) case "$-" in
105) *i*)
106)   stty start ''
107)   stty stop  ''
108)   stty -ixon # disable XON/XOFF flow control
109)   stty ixoff # enable sending (to app) of start/stop characters
110)   stty ixany # let any character restart output, not only start character
111)   ;;
112) *) ;;
113) esac
114) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

121) 
David Blume Add alias for httpie https

David Blume authored 6 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

129)         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

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

137)         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

138)         if [[ -z "${WSL_DISTRO_NAME}" ]]; then
139)             xdg-open $T
140)             echo "rm \"$T\" >/dev/null 2>&1" | at now + 2 minutes
141)         else
142)             # Set BROWSER to your web browser's path
143)             "$BROWSER" $(realpath --relative-to=$PWD $T)
144)         fi
David Blume Add a command for viewing M...

David Blume authored 5 years ago

145)     fi
146) }
147) 
David Blume I almost always want to do...

David Blume authored 4 years ago

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

David Blume authored 4 years ago

149)     # apropos -s 7 . | awk '!/iso|latin/ {print $1}' | shuf -n 1 | xargs man 7
150)     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

151) }
152) 
David Blume Added venv command

David Blume authored 3 years ago

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

David Blume authored 3 years ago

154)     # Inspired by https://twitter.com/gvanrossum/status/1319328122618048514
155)     if hash deactivate 2>/dev/null; then
156)         deactivate
157)     fi
158)     if [[ $1 ]]; then
159)         if [ ! -f $1/bin/activate ]; then
160)             echo "Creating with: python3 -m venv $1"
161)             python3 -m venv $1
David Blume Added venv command

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

164)     fi
165) }
166) 
David Blume Moving ignoredups:erasedups...

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 4 years ago

170) #HISTFILESIZE=2000
171) #HISTSIZE=2000
172) # [ $(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

173) shopt -s histappend
174) 
David Blume Forgot a corresponding chan...

David Blume authored 8 years ago

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

David Blume authored 8 years ago

176)     source $HOME/.localrc