My configuration files for Debian/Ubuntu applications
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

.bashrc 8.3 KiB

hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. # ~/.bashrc: executed by bash(1) for non-login shells.
  2. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
  3. # for examples
  4. # If not running interactively, don't do anything
  5. case $- in
  6. *i*) ;;
  7. *) return;;
  8. esac
  9. # don't put duplicate lines or lines starting with space in the history.
  10. # See bash(1) for more options
  11. HISTCONTROL=ignoreboth
  12. # append to the history file, don't overwrite it
  13. shopt -s histappend
  14. # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
  15. HISTSIZE=1000
  16. HISTFILESIZE=2000
  17. # check the window size after each command and, if necessary,
  18. # update the values of LINES and COLUMNS.
  19. shopt -s checkwinsize
  20. # If set, the pattern "**" used in a pathname expansion context will
  21. # match all files and zero or more directories and subdirectories.
  22. #shopt -s globstar
  23. # make less more friendly for non-text input files, see lesspipe(1)
  24. #[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  25. # set variable identifying the chroot you work in (used in the prompt below)
  26. if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
  27. debian_chroot=$(cat /etc/debian_chroot)
  28. fi
  29. # set a fancy prompt (non-color, unless we know we "want" color)
  30. case "$TERM" in
  31. xterm-color|*-256color) color_prompt=yes;;
  32. esac
  33. # uncomment for a colored prompt, if the terminal has the capability; turned
  34. # off by default to not distract the user: the focus in a terminal window
  35. # should be on the output of commands, not on the prompt
  36. #force_color_prompt=yes
  37. if [ -n "$force_color_prompt" ]; then
  38. if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  39. # We have color support; assume it's compliant with Ecma-48
  40. # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  41. # a case would tend to support setf rather than setaf.)
  42. color_prompt=yes
  43. else
  44. color_prompt=
  45. fi
  46. fi
  47. if [ "$color_prompt" = yes ]; then
  48. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  49. else
  50. PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  51. fi
  52. unset color_prompt force_color_prompt
  53. # If this is an xterm set the title to user@host:dir
  54. case "$TERM" in
  55. xterm*|rxvt*)
  56. PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  57. ;;
  58. *)
  59. ;;
  60. esac
  61. # enable color support of ls and also add handy aliases
  62. if [ -x /usr/bin/dircolors ]; then
  63. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  64. alias ls='ls --color=auto'
  65. #alias dir='dir --color=auto'
  66. #alias vdir='vdir --color=auto'
  67. #alias grep='grep --color=auto'
  68. #alias fgrep='fgrep --color=auto'
  69. #alias egrep='egrep --color=auto'
  70. fi
  71. # colored GCC warnings and errors
  72. #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
  73. # some more ls aliases
  74. #alias ll='ls -l'
  75. #alias la='ls -A'
  76. #alias l='ls -CF'
  77. # Alias definitions.
  78. # You may want to put all your additions into a separate file like
  79. # ~/.bash_aliases, instead of adding them here directly.
  80. # See /usr/share/doc/bash-doc/examples in the bash-doc package.
  81. if [ -f ~/.bash_aliases ]; then
  82. . ~/.bash_aliases
  83. fi
  84. # enable programmable completion features (you don't need to enable
  85. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  86. # sources /etc/bash.bashrc).
  87. if ! shopt -oq posix; then
  88. if [ -f /usr/share/bash-completion/bash_completion ]; then
  89. . /usr/share/bash-completion/bash_completion
  90. elif [ -f /etc/bash_completion ]; then
  91. . /etc/bash_completion
  92. fi
  93. fi
  94. # Directory changes
  95. alias cdn='vim ~/Notes "+cd ~/Notes" "+enew" "+CtrlP"'
  96. alias cdd='cd $HOME/Downloads/'
  97. alias cdo='cd $HOME/Source/'
  98. alias cdc='cd $HOME/.config/'
  99. alias cd-projects='cd $HOME/Projects/'
  100. alias cd-x='cd $HOME/Encrypted/x/'
  101. alias cd-vim='cd /usr/share/vim/vim82/pack/my-plugins/start'
  102. alias cdz='cd $((mru listdirs | fzf --height=50%) || printf ".")'
  103. # General
  104. alias v='vim'
  105. alias yt='youtube-dl'
  106. alias ytb='youtube-dl --no-progress'
  107. alias depth='echo $SHLVL'
  108. alias lsg='ls -la | grep' #Determines if a file or folder with a name containing a sequence of characters is in the current directory
  109. alias show='apt show'
  110. alias lynx='lynx -vikeys'
  111. alias lsa='ls -laF'
  112. alias doihave='apt list --installed'
  113. alias email='neomutt'
  114. # Utilities
  115. alias ins='sudo apt-get install'
  116. alias uns='sudo apt-get purge'
  117. alias update='sudo apt-get update; sudo apt-get upgrade;'
  118. alias nnn='nnn -xE'
  119. alias do-xbind='xbindkeys -f $HOME/Source/configs/xbindkeysrc'
  120. alias get-rndnum='head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8'
  121. alias music="ncmpcpp"
  122. # Programming
  123. alias py='ipython3 --TerminalInteractiveShell.editing_mode=vi'
  124. alias g='git'
  125. alias gc='git clone'
  126. alias gs='git status'
  127. alias ga='git add'
  128. alias gb='git branch'
  129. alias gl='git log'
  130. alias gd='git diff'
  131. # Edit config and system files
  132. alias edit-bashrc='vim $HOME/.bashrc'
  133. alias edit-profile='vim $HOME/.profile'
  134. alias edit-vimrc='sudo vim /etc/vim/vimrc.local'
  135. alias edit-xkb='vim $HOME/.config/xkb/custom.xkb'
  136. alias edit-xr='vim ~/.config/xfiles/Xresources'
  137. alias edit-sources='sudo vim /etc/apt/sources.list'
  138. alias edit-tmux='vim $HOME/.config/tmux/tmux.conf'
  139. alias edit-git='vim $HOME/.config/git/config'
  140. alias load-xr='xrdb ~/.config/xfiles/Xresources'
  141. alias load-xkb='xkbcomp $HOME/.config/xkb/custom.xkb $DISPLAY'
  142. alias load-xt='xrdb $HOME/.config/Xresources'
  143. alias load-profile='source $HOME/.profile'
  144. alias lo='load-profile'
  145. alias betterXev="xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf \"%-3s %s\\n\", $5, $8 }'"
  146. # Encryption
  147. alias mntx='encfs $HOME/Encrypted/.x/ $HOME/Encrypted/x/'
  148. alias umntx='encfs -u $HOME/Encrypted/x/'
  149. # Applications
  150. alias scan='sudo arp-scan 192.168.0.1/24'
  151. alias weechat='weechat -d "$XDG_CONFIG_HOME"/weechat'
  152. #Special functions! :D
  153. search() {
  154. apt search $@ | less
  155. }
  156. clean() {
  157. #Check if there is too many arguments
  158. if [ "$#" -gt "1" ]
  159. then
  160. echo "Too many arguments. There are $#."
  161. return
  162. fi
  163. case "$1" in
  164. '')
  165. ;;
  166. soft)
  167. history -c ;;
  168. hard)
  169. history -c
  170. rm -r $HOME/tmp/; mkdir $HOME/tmp/ ;;
  171. *)
  172. echo "Invalid arguments"; return ;;
  173. esac
  174. echo "History clear"
  175. sudo apt-get autoremove #Cleanup packages
  176. echo "Clean complete"
  177. }
  178. firewall() {
  179. if [ "$#" -gt "1" ]
  180. then
  181. echo "Too many arguments. There are $#."
  182. return
  183. fi
  184. case "$1" in
  185. on)
  186. sudo iptables -F
  187. #Allows lo, allows SSH in, allows packets related to connections established with output
  188. sudo iptables -A walkin -i lo -j ACCEPT
  189. sudo iptables -A walkin -p tcp --dport 22 -j ACCEPT
  190. sudo iptables -A walkin -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  191. #Allows lo, allows ssh out, allows connections out that are owned by root, allows vpn
  192. sudo iptables -A walkout -o lo -j ACCEPT
  193. sudo iptables -A walkout -p tcp --dport 22 -j ACCEPT
  194. sudo iptables -A walkout -m owner --uid-owner root -j ACCEPT
  195. sudo iptables -A walkout -o tun0 -j ACCEPT
  196. sudo iptables -A INPUT -j walkin
  197. sudo iptables -A INPUT -j DROP
  198. sudo iptables -A OUTPUT -j walkout
  199. sudo iptables -A OUTPUT -j DROP
  200. #Not needed
  201. sudo iptables -P INPUT DROP
  202. sudo iptables -P OUTPUT DROP
  203. echo "Firewall is on"
  204. ;;
  205. off)
  206. sudo iptables -F
  207. sudo iptables -P INPUT ACCEPT
  208. sudo iptables -P OUTPUT ACCEPT
  209. echo "Firewall is off"
  210. ;;
  211. *)
  212. echo "Invalid arguments"; return ;;
  213. esac
  214. }
  215. define() {
  216. dict $1 | less;
  217. }
  218. n () {
  219. # Block nesting of nnn in subshells
  220. if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then
  221. echo "nnn is already running"
  222. return
  223. fi
  224. # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
  225. # To cd on quit only on ^G, remove the "export" as in:
  226. # NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
  227. # NOTE: NNN_TMPFILE is fixed, should not be modified
  228. NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
  229. # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
  230. # stty start undef
  231. # stty stop undef
  232. # stty lwrap undef
  233. # stty lnext undef
  234. nnn "$@"
  235. if [ -f "$NNN_TMPFILE" ]; then
  236. . "$NNN_TMPFILE"
  237. rm -f "$NNN_TMPFILE" > /dev/null
  238. fi
  239. }
  240. rebind() {
  241. sudo cp "$1" /usr/local/bin/
  242. }
  243. export GOPATH="$HOME/go"
  244. export GO111MODULE=on
  245. export EDITOR='vim'
  246. export PAGER='less'
  247. export NNN_BMS='h:~/;c:~/.config;n:~/Notes;m:/mnt/media'
  248. export NNN_FIFO=/tmp/nnn.fifo
  249. export NNN_PLUG='p:preview-tui;c:x2sel;i:imgview;s:tmspawn'
  250. export USE_PISTOL=0
  251. export XDG_CONFIG_HOME=$HOME/.config
  252. export XDG_CACHE_HOME=$HOME/.cache
  253. export XDG_DATA_HOME=$HOME/.local/share