My configuration files for Debian/Ubuntu applications
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

329 行
9.0 KiB

  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. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[\033[01;34m\]\W §\[\033[00m\] '
  50. PS4='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[\033[01;34m\]\W §\[\033[00m\] '
  51. # PROMPT_DIRTRIM=3
  52. else
  53. PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  54. fi
  55. unset color_prompt force_color_prompt
  56. # If this is an xterm set the title to user@host:dir
  57. case "$TERM" in
  58. xterm*|rxvt*)
  59. PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  60. ;;
  61. *)
  62. ;;
  63. esac
  64. # enable color support of ls and also add handy aliases
  65. if [ -x /usr/bin/dircolors ]; then
  66. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  67. alias ls='ls --color=auto'
  68. #alias dir='dir --color=auto'
  69. #alias vdir='vdir --color=auto'
  70. #alias grep='grep --color=auto'
  71. #alias fgrep='fgrep --color=auto'
  72. #alias egrep='egrep --color=auto'
  73. fi
  74. # colored GCC warnings and errors
  75. #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
  76. # some more ls aliases
  77. #alias ll='ls -l'
  78. #alias la='ls -A'
  79. #alias l='ls -CF'
  80. # Alias definitions.
  81. # You may want to put all your additions into a separate file like
  82. # ~/.bash_aliases, instead of adding them here directly.
  83. # See /usr/share/doc/bash-doc/examples in the bash-doc package.
  84. if [ -f ~/.bash_aliases ]; then
  85. . ~/.bash_aliases
  86. fi
  87. # enable programmable completion features (you don't need to enable
  88. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  89. # sources /etc/bash.bashrc).
  90. if ! shopt -oq posix; then
  91. if [ -f /usr/share/bash-completion/bash_completion ]; then
  92. . /usr/share/bash-completion/bash_completion
  93. elif [ -f /etc/bash_completion ]; then
  94. . /etc/bash_completion
  95. fi
  96. fi
  97. #Special Settings
  98. set -o vi
  99. #Directory changes
  100. alias cdn='cd $HOME/Notes/; vim "+CtrlP"'
  101. alias cdd='cd $HOME/Downloads/'
  102. alias cdo='cd $HOME/Source/'
  103. alias cdc='cd $HOME/.config/'
  104. alias cd-projects='cd $HOME/Projects/'
  105. alias cd-x='cd $HOME/Encrypted/x/'
  106. alias cd-vim='cd /usr/share/vim/vim82/pack/my-plugins/start'
  107. #General
  108. alias v='vim'
  109. alias yt='youtube-dl'
  110. alias ytb='youtube-dl --no-progress'
  111. alias depth='echo $SHLVL'
  112. alias lsg='ls -la | grep' #Determines if a file or folder with a name containing a sequence of characters is in the current directory
  113. alias show='apt show'
  114. alias lynx='lynx -vikeys'
  115. alias lsa='ls -laF'
  116. alias doihave='apt list --installed'
  117. #Utilities
  118. alias ins='sudo apt-get install'
  119. alias uns='sudo apt-get purge'
  120. alias update='sudo apt-get update; sudo apt-get upgrade;'
  121. alias rn='ranger'
  122. alias nnn='nnn -xE'
  123. alias util-dropdown="st -c 'DROPDOWN_TERM' -e 'tmux' &"
  124. #Programming
  125. alias py='ipython3 --TerminalInteractiveShell.editing_mode=vi'
  126. alias gc='git clone'
  127. # Edit config and system files
  128. alias edit-bashrc='vim $HOME/.bashrc'
  129. alias edit-profile='vim $HOME/.profile'
  130. alias edit-vimrc='sudo vim /etc/vim/vimrc.local'
  131. alias edit-xkb='vim $HOME/.config/xkb/custom.xkb'
  132. alias edit-xr='vim ~/.config/xfiles/Xresources'
  133. alias edit-sources='sudo vim /etc/apt/sources.list'
  134. alias edit-tmux='vim $HOME/.config/tmux/tmux.conf'
  135. alias edit-git='vim $HOME/.config/git/config'
  136. alias load-xr='xrdb ~/.config/xfiles/Xresources'
  137. alias load-xkb='xkbcomp $HOME/.config/xkb/custom.xkb $DISPLAY'
  138. alias load-xt='xrdb $HOME/.config/Xresources'
  139. alias load-profile='source $HOME/.profile'
  140. alias lo='load-profile'
  141. alias betterXev="xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf \"%-3s %s\\n\", $5, $8 }'"
  142. #Encryption
  143. alias mntx='encfs $HOME/Encrypted/.x/ $HOME/Encrypted/x/'
  144. alias umntx='encfs -u $HOME/Encrypted/x/'
  145. #Applications
  146. alias scan='sudo arp-scan 192.168.0.1/24'
  147. alias weechat='weechat -d "$XDG_CONFIG_HOME"/weechat'
  148. #BASE16_SHELL="$HOME/.config/base16-shell/"
  149. # [ -n "$PS1" ] && \
  150. # [ -s "$BASE16_SHELL/profile_helper.sh" ] && \
  151. # eval "$("$BASE16_SHELL/profile_helper.sh")"
  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. wall(){
  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. #adb commands for moving files between the desktop and an android.
  216. apull () {
  217. adb shell ls '/storage/self/primary/Download/'$1 | tr -d '\r' | xargs -n1 adb pull
  218. }
  219. als(){
  220. adb shell ls /storage/self/primary/Download/$1
  221. }
  222. apush() {
  223. adb push "$1" /storage/self/primary/Download;
  224. }
  225. poly() {
  226. # Terminate already running bar instances
  227. killall -q polybar
  228. # Wait until the processes have been shut down
  229. while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
  230. cp -r $XDG_CONFIG_HOME/polybar/bars/polybar-$1/* $XDG_CONFIG_HOME/polybar/
  231. cp -r $XDG_CONFIG_HOME/polybar/fonts/* ~/.local/share/fonts
  232. fc-cache
  233. $XDG_CONFIG_HOME/polybar/launch.sh
  234. }
  235. vpn() {
  236. nmcli connect $1 $2.protonvpn.com.udp
  237. }
  238. define() {
  239. dict $1 | less;
  240. }
  241. n () {
  242. # Block nesting of nnn in subshells
  243. if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then
  244. echo "nnn is already running"
  245. return
  246. fi
  247. # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
  248. # To cd on quit only on ^G, remove the "export" as in:
  249. # NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
  250. # NOTE: NNN_TMPFILE is fixed, should not be modified
  251. NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
  252. # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
  253. # stty start undef
  254. # stty stop undef
  255. # stty lwrap undef
  256. # stty lnext undef
  257. nnn "$@"
  258. if [ -f "$NNN_TMPFILE" ]; then
  259. . "$NNN_TMPFILE"
  260. rm -f "$NNN_TMPFILE" > /dev/null
  261. fi
  262. }
  263. compare() {
  264. git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative $1..$2;
  265. }
  266. blaunch() {
  267. BASE16_SHELL="$HOME/.config/base16-shell/"
  268. [ -n "$PS1" ] && \
  269. [ -s "$BASE16_SHELL/profile_helper.sh" ] && \
  270. eval "$("$BASE16_SHELL/profile_helper.sh")"
  271. }