.bashrc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. # Bash initialization for interactive non-login shells and
  2. # for remote shells (info "(bash) Bash Startup Files").
  3. # Export 'SHELL' to child processes. Programs such as 'screen'
  4. # honor it and otherwise use /bin/sh.
  5. export SHELL
  6. if [[ $- != *i* ]]; then
  7. # We are being invoked from a non-interactive shell. If this
  8. # is an SSH session (as in "ssh host command"), source
  9. # /etc/profile so we get PATH and other essential variables.
  10. [[ -n "$SSH_CLIENT" ]] && source /etc/profile
  11. # Don't do anything else.
  12. return
  13. fi
  14. # Source the system-wide file.
  15. if [ -f /etc/bashrc ]; then
  16. source /etc/bashrc
  17. fi
  18. ############
  19. # MOTD
  20. ############
  21. echo "$(tput setaf 2)
  22. |
  23. | GNU en `hostname`
  24. | `date +"%A, %e %B %Y, %r"`
  25. | Linux-Libre `uname -rm`
  26. | $(tput setaf 1)
  27. $(tput sgr0)"
  28. if hash cowsay 2>/dev/null && hash fortune 2>/dev/null; then
  29. export DAIKICHI_FORTUNE_PATH="$HOME/.fortunes/fortunes/es:$DAIKICHI_FORTUNE_PATH"
  30. fortune ciencia vida libertad hackers liberacion anarchism | cowsay -f "$HOME/.cowsay/small.cow"
  31. fi
  32. #######################
  33. # Alias definitions
  34. #######################
  35. # You may want to put all your additions into a separate file like
  36. # ~/.bash_aliases, instead of adding them here directly.
  37. alias screen="screen -aAxRl"
  38. if [ -f ~/.bash_aliases ]; then
  39. source ~/.bash_aliases
  40. fi
  41. ########################
  42. # Init management
  43. ########################
  44. # SSH management
  45. if hash keychain 2>/dev/null; then
  46. eval $(keychain --eval --noask --quiet)
  47. else
  48. SSH_PID="$XDG_RUNTIME_DIR/ssh-agent.pid"
  49. if ! pgrep -u "$USER" ssh-agent > /dev/null; then
  50. ssh-agent > "$SSH_PID"
  51. fi
  52. if [[ ! "$SSH_AUTH_SOCK" ]] && [[ -f "$SSH_PID" ]]; then
  53. eval "$(<"$SSH_PID")" > /dev/null
  54. fi
  55. fi
  56. # Start GNU Screen
  57. #[[ -z "$STY" ]] && screen
  58. #[[ $TERM != "screen" ]] && exec screen -q
  59. ########################
  60. # Shell Variables
  61. ########################
  62. export EDITOR="emacsclient"
  63. #export EDITOR="$(if [[ -n $DISPLAY ]]; then echo 'em'; else echo 'emc'; fi)"
  64. #export GIT_EDITOR="$(if [[ -n $DISPLAY ]]; then echo 'git-editor'; else echo 'emc'; fi)"
  65. export RANGER_LOAD_DEFAULT_RC=FALSE
  66. #Custom PATH
  67. PATH="$HOME/.scripts/:$HOME/.local/bin/:$PATH"
  68. # don't put duplicate lines in the history. See bash(1) for more options
  69. # ... or force ignoredups and ignorespace
  70. HISTCONTROL=ignoredups:ignorespace
  71. # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
  72. HISTSIZE=1000
  73. HISTFILESIZE=2000
  74. #######################
  75. # Set shell behavior
  76. #######################
  77. # append to the history file, don't overwrite it
  78. shopt -s histappend
  79. # check the window size after each command and, if necessary,
  80. # update the values of LINES and COLUMNS.
  81. shopt -s checkwinsize
  82. # Disable completion when the input buffer is empty. i.e. Hitting tab
  83. # and waiting a long time for bash to expand all of $PATH.
  84. shopt -s no_empty_cmd_completion
  85. # make less more friendly for non-text input files, see lesspipe(1)
  86. [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  87. #############################
  88. # Distribution configuration
  89. #############################
  90. # On Debian set variable identifying the chroot you work in (used in the prompt below)
  91. if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  92. debian_chroot=$(cat /etc/debian_chroot)
  93. chroot_prompt="${debian_chroot:+($debian_chroot)}"
  94. fi
  95. #######################
  96. # Colors support
  97. #######################
  98. # Force Enable urxvt 256 colors support
  99. export TERM=xterm-256color
  100. # set a fancy prompt (non-color, unless we know we "want" color)
  101. case "$TERM" in
  102. [aEkx]term*|rxvt*|gnome*|konsole*|screen|cons25|*color) color_prompt=yes;;
  103. esac
  104. # uncomment for a colored prompt, if the terminal has the capability; turned
  105. # off by default to not distract the user: the focus in a terminal window
  106. # should be on the output of commands, not on the prompt
  107. #force_color_prompt=yes
  108. if [ -n "$force_color_prompt" ]; then
  109. if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  110. # We have color support; assume it's compliant with Ecma-48
  111. # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  112. # a case would tend to support setf rather than setaf.)
  113. color_prompt=yes
  114. else
  115. color_prompt=no
  116. fi
  117. fi
  118. #######################
  119. # Prompt setup
  120. #######################
  121. # Adjust the prompt depending on whether we're in 'guix environment'.
  122. if [ -n "$GUIX_ENVIRONMENT" ]; then
  123. env_prompt=' [env]'
  124. else
  125. env_prompt=''
  126. fi
  127. if [ "$color_prompt" = yes ]; then
  128. # default: PS1='\u@\h \w\$ '
  129. PS1='${chroot_prompt}\[\e[0;0m\]┌─ \u\[\e[33;1m\]@\h \[\033[01;34m\]\W${env_prompt}\[\033[00m\] \[\e[0;1m\]\n└──┤|▶ \[\e[0m\]'
  130. else
  131. PS1='${chroot_prompt}\u@\h \W${env_prompt}\$ '
  132. fi
  133. unset color_prompt force_color_prompt
  134. # # Change the window title of X terminals
  135. case ${TERM} in
  136. [aEkx]term*|rxvt*|gnome*|konsole*|interix)
  137. PS1="\[\e]0;${chroot_prompt}\u@\h:\w\a\]$PS1"
  138. ;;
  139. screen*)
  140. PS1="\[\033k${chroot_prompt}\u@\h:\w\033\\\]$PS1"
  141. ;;
  142. *)
  143. ;;
  144. esac
  145. # GuixSD needs this? it still requesting it
  146. # Arrange so that ~/.config/guix/current comes first.
  147. for profile in "$HOME/.guix-profile" "$HOME/.config/guix/current"
  148. do
  149. if [ -f "$profile/etc/profile" ]
  150. then
  151. # Load the user profile's settings.
  152. GUIX_PROFILE="$profile" ; \
  153. . "$profile/etc/profile"
  154. else
  155. # At least define this one so that basic things just work
  156. # when the user installs their first package.
  157. export PATH="$profile/bin:$PATH"
  158. fi
  159. done
  160. unset profile
  161. ##########################
  162. # Load additional path
  163. # definitions
  164. ##########################
  165. #Node.js Tools
  166. export PNPM_HOME="$HOME/.local/share/pnpm"
  167. case ":$PATH:" in
  168. *":$PNPM_HOME:"*) ;;
  169. *) export PATH="$PNPM_HOME:$PATH" ;;
  170. esac
  171. #export NVM_DIR="$HOME/.nvm"
  172. #[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  173. #[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
  174. ###########################
  175. # Completion configuration
  176. ###########################
  177. # Enable programmable completion features, For non GuixSD systems but maybe not
  178. # need due /etc/bashrc is already source.
  179. if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
  180. source /etc/bash_completion
  181. fi
  182. ###-begin-npm-completion-###
  183. #
  184. # npm command completion script
  185. #
  186. # Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
  187. # Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
  188. #
  189. if type complete &>/dev/null; then
  190. _npm_completion () {
  191. local words cword
  192. if type _get_comp_words_by_ref &>/dev/null; then
  193. _get_comp_words_by_ref -n = -n @ -w words -i cword
  194. else
  195. cword="$COMP_CWORD"
  196. words=("${COMP_WORDS[@]}")
  197. fi
  198. local si="$IFS"
  199. IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
  200. COMP_LINE="$COMP_LINE" \
  201. COMP_POINT="$COMP_POINT" \
  202. npm completion -- "${words[@]}" \
  203. 2>/dev/null)) || return $?
  204. IFS="$si"
  205. }
  206. complete -o default -F _npm_completion npm
  207. elif type compdef &>/dev/null; then
  208. _npm_completion() {
  209. local si=$IFS
  210. compadd -- $(COMP_CWORD=$((CURRENT-1)) \
  211. COMP_LINE=$BUFFER \
  212. COMP_POINT=0 \
  213. npm completion -- "${words[@]}" \
  214. 2>/dev/null)
  215. IFS=$si
  216. }
  217. compdef _npm_completion npm
  218. elif type compctl &>/dev/null; then
  219. _npm_completion () {
  220. local cword line point words si
  221. read -Ac words
  222. read -cn cword
  223. let cword-=1
  224. read -l line
  225. read -ln point
  226. si="$IFS"
  227. IFS=$'\n' reply=($(COMP_CWORD="$cword" \
  228. COMP_LINE="$line" \
  229. COMP_POINT="$point" \
  230. npm completion -- "${words[@]}" \
  231. 2>/dev/null)) || return $?
  232. IFS="$si"
  233. }
  234. compctl -K _npm_completion npm
  235. fi
  236. ###-end-npm-completion-###
  237. ###########################
  238. # Isolate project env
  239. ###########################
  240. eval "$(direnv hook bash)"