eb37046eb1d17eade5579fc2fc6125fed7332ad6
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 No need for __git_ps1 if no...

dblume authored 2 years ago

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

dblume authored 3 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 3 years ago

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

dblume authored 3 years ago

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

dblume authored 3 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 3 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 3 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 3 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 3 years ago

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

dblume authored 3 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 3 years ago

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

dblume authored 3 years ago

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

dblume authored 3 years ago

37) 
dblume Try to source __git_ps1 fir...

dblume authored 3 years ago

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

dblume authored 3 years ago

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

dblume authored 3 years ago

41) 
dblume Add Docker container to PS1

dblume authored 2 years ago

42) # Trim everything before the dash, then trim everything after the colon.
dblume Stop exporting PS1 behind S...

dblume authored 2 years ago

43) PS1_DOCKER_VER=${DOCKER_VER#*-}
44) PS1_DOCKER_VER="🐳 \e[0;36m${PS1_DOCKER_VER%:*}"
dblume Add Docker container to PS1

dblume authored 2 years ago

45) 
dblume Stop exporting PS1 behind S...

dblume authored 2 years ago

46) # In PS1, "\h" is hostname
dblume Add Docker container to PS1

dblume authored 2 years ago

47) if [[ -n $SSH_CLIENT ]]; then
dblume Stop exporting PS1 behind S...

dblume authored 2 years ago

48)     PS1_HOSTNAME="$HOSTNAME:"
David Blume New PS1 with error detectio...

David Blume authored 6 years ago

49) else
dblume Stop exporting PS1 behind S...

dblume authored 2 years ago

50)     PS1_HOSTNAME=
David Blume New PS1 with error detectio...

David Blume authored 6 years ago

51) fi
52) 
dblume Stop exporting PS1 behind S...

dblume authored 2 years ago

53) export PROMPT_DIRTRIM=2
54) export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
55)               else echo -e "\[\e[31m\]\xe2\x9c\x97";
56)               fi)$(if [ -n "$DOCKER_VER" ]; then echo -e " $PS1_DOCKER_VER";
57)               fi) \[\e[38;5;242m\]$PS1_HOSTNAME\w$(__git_ps1 " \[\e[38;5;030m\]%s\[\e[38;5;242m\]")$\[\e[0m\] '
58) 
David Blume New PS1 with error detectio...

David Blume authored 6 years ago

59) set -o vi
David Blume first commit

David Blume authored 8 years ago

60) 
dblume Cleaner appending to PATH

dblume authored 1 year ago

61) append_to_path() {
David Blume first commit

David Blume authored 8 years ago

62)     if [ -d "$1" ] && [[ ! $PATH =~ (^|:)$1(:|$) ]]; then
63)         PATH+=:$1
64)     fi
65) }
66) 
dblume Cleaner appending to PATH

dblume authored 1 year ago

67) prepend_to_path() {
68)     if [ -d "$1" ] && [[ ! $PATH =~ (^|:)$1(:|$) ]]; then
69)         PATH=$1:$PATH
70)     fi
71) }
72) 
dblume Add remove_from_path to .ba...

dblume authored 1 year ago

73) remove_from_path() {
74)     # N.B. It'll remove all instances of $1, so ensure it's a unique pathname
75)     PATH=${PATH//"$1"/}
76) }
77) 
David Blume first commit

David Blume authored 8 years ago

78) # if this is a CygWin .bashrc, then set CygWin's commands first in PATH
79) # because link.exe and find.exe exist in Windows's path.
80) # Add /usr/lib/lapack at the end so python's numpy can find lapack_lite
81) # (Note: BSD bash, used by OS X doesn't have the "substr" test for expr.)
82) if [[ $(uname -s) == CYGWIN* ]]; then
dblume Add remove_from_path to .ba...

dblume authored 1 year ago

83)     prepend_to_path /usr/bin
84)     prepend_to_path /usr/local/bin
85)     remove_from_path ":/usr/local/bin:/usr/bin"
dblume Cleaner appending to PATH

dblume authored 1 year ago

86)     append_to_path /usr/lib/lapack
David Blume Add md() support for Cygwin...

David Blume authored 5 years ago

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

David Blume authored 8 years ago

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

David Blume authored 4 years ago

89) elif [[ -n "${WSL_DISTRO_NAME}" ]]; then
90)     export BROWSER=/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe
dblume Add pbcopy for WSL2

dblume authored 2 years ago

91)     alias pbcopy='tee <&0 | /mnt/c/Windows/System32/clip.exe'
dblume Disable inotify for WSL tai...

dblume authored 1 year ago

92)     alias tail='tail ---disable-inotify'
David Blume first commit

David Blume authored 8 years ago

93) fi
94) 
David Blume whitespace

David Blume authored 6 years ago

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

David Blume authored 8 years ago

96) if [[ $(uname -s) == Darwin* ]]; then
97)     export LSCOLORS=gxfxcxdxbxegedabagacad
98)     export CLICOLOR=1
99) else
100)     # After executing: dircolors -p > .dircolors
101)     # Lighten the color of directories from blue to light blue
102)     # sed -i '/# directory/c\DIR 00;36 # directory' .dircolors
103)     if [ -x /usr/bin/dircolors ]; then
104)         test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
105)         alias ls='ls --color=auto'
106)     fi
David Blume first commit

David Blume authored 8 years ago

107) fi
108) 
David Blume Add .vimrc tab values for ....

David Blume authored 8 years ago

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

110) export CSCOPE_EDITOR=vim
dblume Add .ripgreprc for ripgrep,...

dblume authored 2 years ago

111) export RIPGREP_CONFIG_PATH=$HOME/.ripgreprc
David Blume Add .vimrc tab values for ....

David Blume authored 8 years ago

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

David Blume authored 8 years ago

113) alias grep='grep --color=auto'
114) alias fgrep='fgrep --color=auto'
115) alias egrep='egrep --color=auto'
dblume vim: Use more common char f...

dblume authored 3 years ago

116) alias tmux='tmux -2u'
dblume Make test for nvim compatib...

dblume authored 7 months ago

117) if command -v nvim &> /dev/null; then
dblume Have the command "vim" laun...

dblume authored 8 months ago

118)     alias vim='nvim'
119)     alias vim-='nvim +"setl buftype=nofile" -'
120)     alias vimdiff='nvim -d'
121) else
122)     alias vim-='vim +"setl buftype=nofile" -'
123) fi
David Blume Add alias for colors in ls...

David Blume authored 8 years ago

124) 
125) # colored GCC warnings and errors
126) export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
127) 
dblume Move ~/.local/bin ahead of...

dblume authored 11 months ago

128) # .local/bin must come before /usr/bin and /bin for VisiData and clang-format
129) remove_from_path $HOME/.local/bin
130) prepend_to_path $HOME/.local/bin
dblume Add .local/bin to $PATH

dblume authored 1 year ago

131) # Add to PATH only if not already in PATH.
dblume Cleaner appending to PATH

dblume authored 1 year ago

132) append_to_path $HOME/bin
dblume Add .local/bin to $PATH

dblume authored 1 year ago

133) # .cargo/bin for rustc
dblume Add rust to $PATH

dblume authored 1 year ago

134) append_to_path $HOME/.cargo/bin
David Blume first commit

David Blume authored 8 years ago

135) 
David Blume disable ctrl+s as stty flow...

David Blume authored 3 years ago

136) # For interactive shells ('i' in $-), disable stty flow control (ctrl+s,ctrl+q)
137) case "$-" in
dblume Set CDPATH for interactive...

dblume authored 2 years ago

138)  *i*)
David Blume disable ctrl+s as stty flow...

David Blume authored 3 years ago

139)   stty start ''
140)   stty stop  ''
141)   stty -ixon # disable XON/XOFF flow control
142)   stty ixoff # enable sending (to app) of start/stop characters
143)   stty ixany # let any character restart output, not only start character
dblume Set CDPATH for interactive...

dblume authored 2 years ago

144) 
dblume Do need to prepend '.' to C...

dblume authored 2 years ago

145)   # Don't use export for CDPATH. This may get appended to in .localrc too.
dblume Add dunst config from Frame...

dblume authored 11 months ago

146)   # You may have to explicitly source /usr/share/bash-completion/bash_completion
dblume Do need to prepend '.' to C...

dblume authored 2 years ago

147)   CDPATH=.:$HOME
dblume Set CDPATH for interactive...

dblume authored 2 years ago

148) 
149)  ;;
David Blume disable ctrl+s as stty flow...

David Blume authored 3 years ago

150) esac
151) 
dblume 'lh' to list only most rece...

dblume authored 9 months ago

152) # Keeping as an example, but haven't used since ripgrep
153) #alias findinchppfiles="find . -type f \( -name \*.[ch]pp -or -name \*.[ch] \) -print0 | xargs -0 grep -nI"
David Blume Add a few c++ aliases, and...

David Blume authored 8 years ago

154) 
155) alias clip="expand | cut -b1-\$COLUMNS"
David Blume Optionally source a .localr...

David Blume authored 8 years ago

156) 
dblume 'lh' now function to accept...

dblume authored 9 months ago

157) # I'm often interested in just the most recently changed file
dblume Add conditional ellipses to lh

dblume authored 9 months ago

158) # N.B. If changing -l to -1, remove tail, because "total" line is only for -l
dblume 'lh' now function to accept...

dblume authored 9 months ago

159) lh() {
dblume lh and lt compatible with m...

dblume authored 9 months ago

160)     if [[ $(uname -s) != Darwin* ]]; then
dblume Change readonly to 'local -r'

dblume authored 9 months ago

161)         local -r color_always="--color=always"
dblume lh and lt compatible with m...

dblume authored 9 months ago

162)     fi
163)     ls $color_always -ltqh "$@" | head -$(($LINES/4)) | tail -n +2
164)     if [ $(ls -1 "$@" | wc -l) -gt $(($LINES/4)) ]; then
dblume Add conditional ellipses to lh

dblume authored 9 months ago

165)         echo ...
166)     fi
dblume 'lh' now function to accept...

dblume authored 9 months ago

167) }
dblume 'lh' to list only most rece...

dblume authored 9 months ago

168) 
dblume Decide if I want 'lt' (ls |...

dblume authored 9 months ago

169) # lh = "ls | head" (newest at top), lt = "ls | tail" (newest at the bottom)
170) lt() {
dblume lh and lt compatible with m...

dblume authored 9 months ago

171)     if [ $(ls -1 "$@" | wc -l) -gt $(($LINES/4)) ]; then
dblume Decide if I want 'lt' (ls |...

dblume authored 9 months ago

172)         echo ...
173)     fi
dblume lh and lt compatible with m...

dblume authored 9 months ago

174)     if [[ $(uname -s) != Darwin* ]]; then
dblume Change readonly to 'local -r'

dblume authored 9 months ago

175)         local -r color_always="--color=always"
dblume lh and lt compatible with m...

dblume authored 9 months ago

176)     fi
177)     ls $color_always -rltqh "$@" | tail -n $(($LINES/4))
dblume Decide if I want 'lt' (ls |...

dblume authored 9 months ago

178) }
dblume Add nvim-

dblume authored 8 months ago

179) # Just so I don't have to use two hands
180) alias ly=lt
dblume Decide if I want 'lt' (ls |...

dblume authored 9 months ago

181) 
David Blume Add alias for httpie https

David Blume authored 6 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

198)         if [[ -z "${WSL_DISTRO_NAME}" ]]; then
dblume Use gio open instead of xdg...

dblume authored 2 years ago

199)             gio open $T
David Blume Add support for 'md' on WSL.

David Blume authored 4 years ago

200)             echo "rm \"$T\" >/dev/null 2>&1" | at now + 2 minutes
201)         else
202)             # Set BROWSER to your web browser's path
dblume Don't call git if not in a...

dblume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 5 years ago

205)     fi
206) }
207) 
David Blume I almost always want to do...

David Blume authored 4 years ago

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

David Blume authored 4 years ago

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

211) }
212) 
David Blume Added venv command

David Blume authored 3 years ago

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

David Blume authored 3 years ago

214)     # Inspired by https://twitter.com/gvanrossum/status/1319328122618048514
215)     if hash deactivate 2>/dev/null; then
216)         deactivate
217)     fi
218)     if [[ $1 ]]; then
219)         if [ ! -f $1/bin/activate ]; then
220)             echo "Creating with: python3 -m venv $1"
221)             python3 -m venv $1
David Blume Added venv command

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

224)     fi
225) }
226) 
David Blume Moving ignoredups:erasedups...

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 4 years ago

230) #HISTFILESIZE=2000
231) #HISTSIZE=2000
232) # [ $(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

233) shopt -s histappend
234) 
David Blume Forgot a corresponding chan...

David Blume authored 8 years ago

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

David Blume authored 8 years ago

236)     source $HOME/.localrc