I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
5.7 KiB

  1. #+TITLE: Shell
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+begin_src shell
  5. ln -s ~/.local/source/dotfiles/config/shell/bashrc ~/.bashrc
  6. ln -s ~/.local/source/dotfiles/config/shell/profile ~/.profile
  7. #+end_src
  8. * Bash
  9. :PROPERTIES:
  10. :header-args: :tangle ~/.local/source/dotfiles/config/shell/bashrc :results silent
  11. :END:
  12. Executed by bash for non-login shells. See ~/usr/share/doc/bash/examples/startup-files~ (in the package =bash-doc=) for examples.
  13. If not running interactively, don't do anything.
  14. #+begin_src shell
  15. case $- in
  16. *i*) ;;
  17. *) return;;
  18. esac
  19. #+end_src
  20. Don't put duplicate lines or lines starting with space in the history.
  21. #+begin_src shell
  22. HISTCONTROL=ignoreboth
  23. #+end_src
  24. Append to the history file, don't overwrite it.
  25. #+begin_src shell
  26. shopt -s histappend
  27. #+end_src
  28. For setting history length see ~HISTSIZE~ and ~HISTFILESIZE~.
  29. #+begin_src shell
  30. HISTSIZE=1000
  31. HISTFILESIZE=2000
  32. #+end_src
  33. Check the window size after each command and, if necessary, update the values of ~LINES~ and ~COLUMNS~.
  34. #+begin_src shell
  35. shopt -s checkwinsize
  36. #+end_src
  37. If set, the pattern ="**"= used in a pathname expansion context will match all files and zero or more directories and subdirectories.
  38. #+begin_src shell
  39. #shopt -s globstar
  40. #+end_src
  41. Make less more friendly for non-text input files.
  42. #+begin_src shell
  43. [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  44. #+end_src
  45. Set variable identifying the chroot you work in (used in the prompt below).
  46. #+begin_src shell
  47. if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
  48. debian_chroot=$(cat /etc/debian_chroot)
  49. fi
  50. #+end_src
  51. Set a fancy prompt (non-color, unless we know we "want" color).
  52. #+begin_src shell
  53. case "$TERM" in
  54. xterm-color|*-256color) color_prompt=yes;;
  55. esac
  56. #+end_src
  57. Uncomment for a colored prompt, if the terminal has the capability; turned off by default to not distract the user: the focus in a terminal window should be on the output of commands, not on the prompt.
  58. #+begin_src shell
  59. #force_color_prompt=yes
  60. #+end_src
  61. If we have color support; assume it's compliant with =Ecma-48 (ISO/IEC-6429)=.
  62. #+begin_src shell
  63. if [ -n "$force_color_prompt" ]; then
  64. if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  65. color_prompt=yes
  66. else
  67. color_prompt=
  68. fi
  69. fi
  70. #+end_src
  71. Lack of such support is extremely rare, and such a case would tend to support ~setf~ rather than ~setaf~.
  72. #+begin_src shell
  73. if [ "$color_prompt" = yes ]; then
  74. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  75. else
  76. PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  77. fi
  78. unset color_prompt force_color_prompt
  79. #+end_src
  80. If this is an xterm set the title to ~user@host:dir~.
  81. #+begin_src shell
  82. case "$TERM" in
  83. xterm*|rxvt*)
  84. PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  85. ;;
  86. *)
  87. ;;
  88. esac
  89. #+end_src
  90. Enable color support of ~ls~ and also add handy aliases.
  91. #+begin_src shell
  92. if [ -x /usr/bin/dircolors ]; then
  93. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  94. alias ls='ls --color=auto'
  95. #alias dir='dir --color=auto'
  96. #alias vdir='vdir --color=auto'
  97. alias grep='grep --color=auto'
  98. alias fgrep='fgrep --color=auto'
  99. alias egrep='egrep --color=auto'
  100. fi
  101. #+end_src
  102. Colored =GCC= warnings and errors.
  103. #+begin_src shell
  104. #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
  105. #+end_src
  106. Some more ~ls~ aliases.
  107. #+begin_src shell
  108. alias ll='ls -alF'
  109. alias la='ls -A'
  110. alias l='ls -CF'
  111. #+end_src
  112. Add an ~alert~ alias for long running commands.
  113. #+begin_src shell
  114. alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
  115. #+end_src
  116. Use like so:
  117. #+begin_example
  118. sleep 10; alert
  119. #+end_example
  120. You may want to put all your additions into a separate file like ~~/.bash_aliases~, instead of adding them here directly. See ~/usr/share/doc/bash-doc/examples~ in the =bash-doc= package.
  121. #+begin_src shell
  122. if [ -f ~/.bash_aliases ]; then
  123. . ~/.bash_aliases
  124. fi
  125. #+end_src
  126. Enable programmable completion features. You don't need to enable this, if it's already enabled in ~/etc/bash.bashrc~ and ~/etc/profile~ sources ~/etc/bash.bashrc~.
  127. #+begin_src shell
  128. if ! shopt -oq posix; then
  129. if [ -f /usr/share/bash-completion/bash_completion ]; then
  130. . /usr/share/bash-completion/bash_completion
  131. elif [ -f /etc/bash_completion ]; then
  132. . /etc/bash_completion
  133. fi
  134. fi
  135. #+end_src
  136. * Profile
  137. :PROPERTIES:
  138. :header-args: :tangle ~/.local/source/dotfiles/config/shell/profile :results silent
  139. :END:
  140. Executed by the command interpreter for login shells.
  141. This file is *not* read by bash, if ~~/.bash_profile~ or ~~/.bash_login~ exists. See =/usr/share/doc/bash/examples/startup-files= for examples. The files are located in the bash-doc package.
  142. The default umask is set in ~/etc/profile~. For =SSH= logins, install and configure the =libpam-umask= package.
  143. #+begin_src shell
  144. #umask 022
  145. #+end_src
  146. If we're running =bash= make sure to include ~~/.bashrc~ if it exists.
  147. #+begin_src shell
  148. if [ -n "$BASH_VERSION" ]; then
  149. if [ -f "$HOME/.bashrc" ]; then
  150. . "$HOME/.bashrc"
  151. fi
  152. fi
  153. #+end_src
  154. Add private bin directories to the ~$PATH~ (if they exist).
  155. + ~$HOME/bin~
  156. + ~$HOME/.local/bin~
  157. #+begin_src shell
  158. if [ -d "$HOME/bin" ]; then
  159. PATH="$HOME/bin:$PATH"
  160. fi
  161. if [ -d "$HOME/.local/bin" ]; then
  162. PATH="$HOME/.local/bin:$PATH"
  163. fi
  164. #+end_src
  165. Add ~$HOME/go/bin~ to the ~$PATH~ if it exists.
  166. #+begin_src shell
  167. if [ -d "$HOME/go/bin" ]; then
  168. PATH="$HOME/go/bin:$PATH"
  169. fi
  170. #+end_src
  171. Auto run =startx= on login if there's no display server running.
  172. #+begin_src shell
  173. if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
  174. exec startx
  175. fi
  176. #+end_src