0e586519e96110465efde0640db60f21cecc5ef2
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 Use __git_ps1 when possible.

dblume authored 3 years ago

7) # Some devices may not have __git_ps1, so fake it
dblume Make local __git_ps1 work a...

dblume authored 3 years ago

8) if ! $(declare -F __git_ps1 >/dev/null); then
dblume Use __git_ps1 when possible.

dblume authored 3 years ago

9)     __git_ps1() {
dblume Make local __git_ps1 work a...

dblume authored 3 years ago

10)         local fmt="${1:-%s}"
11)         local branch=$(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
12)         if [ -n "$branch" ]; then
13)             printf "$fmt" "$branch"
14)         fi
dblume Use __git_ps1 when possible.

dblume authored 3 years ago

15)     }
16) fi
dblume Experiment: Add git branch...

dblume authored 3 years ago

17) 
18) if true ; then
dblume Shorten directory in prompt...

dblume authored 3 years ago

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

dblume authored 3 years ago

20)     # I like 023 or 030 for the git branch color. See https://i.stack.imgur.com/UQVe5.png
21)     if [[ -n $SSH_CLIENT ]]; then
22)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
dblume Make fake __git_ps1 use its...

dblume authored 3 years ago

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

dblume authored 3 years ago

24)     else
25)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
dblume Make fake __git_ps1 use its...

dblume authored 3 years ago

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

dblume authored 3 years ago

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

David Blume authored 6 years ago

28) else
dblume Shorten directory in prompt...

dblume authored 3 years ago

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

dblume authored 3 years ago

30)     if [[ -n $SSH_CLIENT ]]; then
31)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
32)                       else echo -e "\[\e[31m\]\xe2\x9c\x97"; fi) \[\e[38;5;242m\]\h:\w$\[\e[0m\] '
33)     else
34)         export PS1='$(if [ $? -eq 0 ]; then echo -e "\[\e[32m\]\xe2\x9c\x93";
35)                       else echo -e "\[\e[31m\]\xe2\x9c\x97"; fi) \[\e[38;5;242m\]\w$\[\e[0m\] '
36)     fi
David Blume New PS1 with error detectio...

David Blume authored 6 years ago

37) fi
38) 
39) set -o vi
David Blume first commit

David Blume authored 8 years ago

40) 
41) add_to_path() {
42)     if [ -d "$1" ] && [[ ! $PATH =~ (^|:)$1(:|$) ]]; then
43)         PATH+=:$1
44)     fi
45) }
46) 
47) # if this is a CygWin .bashrc, then set CygWin's commands first in PATH
48) # because link.exe and find.exe exist in Windows's path.
49) # Add /usr/lib/lapack at the end so python's numpy can find lapack_lite
50) # (Note: BSD bash, used by OS X doesn't have the "substr" test for expr.)
51) if [[ $(uname -s) == CYGWIN* ]]; then
David Blume Use spaces instead of tabs.

David Blume authored 8 years ago

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

David Blume authored 5 years ago

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

David Blume authored 8 years ago

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

David Blume authored 4 years ago

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

David Blume authored 8 years ago

59) fi
60) 
David Blume whitespace

David Blume authored 6 years ago

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

David Blume authored 8 years ago

62) if [[ $(uname -s) == Darwin* ]]; then
63)     export LSCOLORS=gxfxcxdxbxegedabagacad
64)     export CLICOLOR=1
65) else
66)     # After executing: dircolors -p > .dircolors
67)     # Lighten the color of directories from blue to light blue
68)     # sed -i '/# directory/c\DIR 00;36 # directory' .dircolors
69)     if [ -x /usr/bin/dircolors ]; then
70)         test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
71)         alias ls='ls --color=auto'
72)     fi
David Blume first commit

David Blume authored 8 years ago

73) fi
74) 
David Blume Add .vimrc tab values for ....

David Blume authored 8 years ago

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

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

78) alias grep='grep --color=auto'
79) alias fgrep='fgrep --color=auto'
80) alias egrep='egrep --color=auto'
David Blume I almost always want to do...

David Blume authored 4 years ago

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

David Blume authored 4 years ago

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

David Blume authored 8 years ago

83) 
84) # colored GCC warnings and errors
85) export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
86) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 3 years ago

90) # For interactive shells ('i' in $-), disable stty flow control (ctrl+s,ctrl+q)
91) case "$-" in
92) *i*)
93)   stty start ''
94)   stty stop  ''
95)   stty -ixon # disable XON/XOFF flow control
96)   stty ixoff # enable sending (to app) of start/stop characters
97)   stty ixany # let any character restart output, not only start character
98)   ;;
99) *) ;;
100) esac
101) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

108) 
David Blume Add alias for httpie https

David Blume authored 6 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

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

David Blume authored 5 years ago

132)     fi
133) }
134) 
David Blume I almost always want to do...

David Blume authored 4 years ago

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

David Blume authored 4 years ago

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

138) }
139) 
David Blume Added venv command

David Blume authored 3 years ago

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

David Blume authored 3 years ago

141)     # Inspired by https://twitter.com/gvanrossum/status/1319328122618048514
142)     if hash deactivate 2>/dev/null; then
143)         deactivate
144)     fi
145)     if [[ $1 ]]; then
146)         if [ ! -f $1/bin/activate ]; then
147)             echo "Creating with: python3 -m venv $1"
148)             python3 -m venv $1
David Blume Added venv command

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

151)     fi
152) }
153) 
David Blume Moving ignoredups:erasedups...

David Blume authored 5 years ago

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

David Blume authored 5 years ago

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

David Blume authored 4 years ago

157) #HISTFILESIZE=2000
158) #HISTSIZE=2000
159) # [ $(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

160) shopt -s histappend
161) 
David Blume Forgot a corresponding chan...

David Blume authored 8 years ago

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

David Blume authored 8 years ago

163)     source $HOME/.localrc