My configuration files for Debian/Ubuntu applications
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.
 
 
 
 
 
 

331 line
9.2 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='vim ~/Notes/text "+cd ~/Notes/text" "+enew" "+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. alias do-xbind='xbindkeys -f "$XDG_CONFIG_HOME"/xbindkeys/config'
  125. alias get-rndnum='head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8'
  126. #Programming
  127. alias py='ipython3 --TerminalInteractiveShell.editing_mode=vi'
  128. alias gc='git clone'
  129. # Edit config and system files
  130. alias edit-bashrc='vim $HOME/.bashrc'
  131. alias edit-profile='vim $HOME/.profile'
  132. alias edit-vimrc='sudo vim /etc/vim/vimrc.local'
  133. alias edit-xkb='vim $HOME/.config/xkb/custom.xkb'
  134. alias edit-xr='vim ~/.config/xfiles/Xresources'
  135. alias edit-sources='sudo vim /etc/apt/sources.list'
  136. alias edit-tmux='vim $HOME/.config/tmux/tmux.conf'
  137. alias edit-git='vim $HOME/.config/git/config'
  138. alias load-xr='xrdb ~/.config/xfiles/Xresources'
  139. alias load-xkb='xkbcomp $HOME/.config/xkb/custom.xkb $DISPLAY'
  140. alias load-xt='xrdb $HOME/.config/Xresources'
  141. alias load-profile='source $HOME/.profile'
  142. alias lo='load-profile'
  143. alias betterXev="xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf \"%-3s %s\\n\", $5, $8 }'"
  144. #Encryption
  145. alias mntx='encfs $HOME/Encrypted/.x/ $HOME/Encrypted/x/'
  146. alias umntx='encfs -u $HOME/Encrypted/x/'
  147. #Applications
  148. alias scan='sudo arp-scan 192.168.0.1/24'
  149. alias weechat='weechat -d "$XDG_CONFIG_HOME"/weechat'
  150. #BASE16_SHELL="$HOME/.config/base16-shell/"
  151. # [ -n "$PS1" ] && \
  152. # [ -s "$BASE16_SHELL/profile_helper.sh" ] && \
  153. # eval "$("$BASE16_SHELL/profile_helper.sh")"
  154. #Special functions! :D
  155. search () {
  156. apt search $@ | less
  157. }
  158. clean () {
  159. #Check if there is too many arguments
  160. if [ "$#" -gt "1" ]
  161. then
  162. echo "Too many arguments. There are $#."
  163. return
  164. fi
  165. case "$1" in
  166. '')
  167. ;;
  168. soft)
  169. history -c ;;
  170. hard)
  171. history -c
  172. rm -r $HOME/tmp/; mkdir $HOME/tmp/ ;;
  173. *)
  174. echo "Invalid arguments"; return ;;
  175. esac
  176. echo "History clear"
  177. sudo apt-get autoremove #Cleanup packages
  178. echo "Clean complete"
  179. }
  180. firewall(){
  181. if [ "$#" -gt "1" ]
  182. then
  183. echo "Too many arguments. There are $#."
  184. return
  185. fi
  186. case "$1" in
  187. on)
  188. sudo iptables -F
  189. #Allows lo, allows SSH in, allows packets related to connections established with output
  190. sudo iptables -A walkin -i lo -j ACCEPT
  191. sudo iptables -A walkin -p tcp --dport 22 -j ACCEPT
  192. sudo iptables -A walkin -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  193. #Allows lo, allows ssh out, allows connections out that are owned by root, allows vpn
  194. sudo iptables -A walkout -o lo -j ACCEPT
  195. sudo iptables -A walkout -p tcp --dport 22 -j ACCEPT
  196. sudo iptables -A walkout -m owner --uid-owner root -j ACCEPT
  197. sudo iptables -A walkout -o tun0 -j ACCEPT
  198. sudo iptables -A INPUT -j walkin
  199. sudo iptables -A INPUT -j DROP
  200. sudo iptables -A OUTPUT -j walkout
  201. sudo iptables -A OUTPUT -j DROP
  202. #Not needed
  203. sudo iptables -P INPUT DROP
  204. sudo iptables -P OUTPUT DROP
  205. echo "Firewall is on"
  206. ;;
  207. off)
  208. sudo iptables -F
  209. sudo iptables -P INPUT ACCEPT
  210. sudo iptables -P OUTPUT ACCEPT
  211. echo "Firewall is off"
  212. ;;
  213. *)
  214. echo "Invalid arguments"; return ;;
  215. esac
  216. }
  217. #adb commands for moving files between the desktop and an android.
  218. apull () {
  219. adb shell ls '/storage/self/primary/Download/'$1 | tr -d '\r' | xargs -n1 adb pull
  220. }
  221. als(){
  222. adb shell ls /storage/self/primary/Download/$1
  223. }
  224. apush() {
  225. adb push "$1" /storage/self/primary/Download;
  226. }
  227. poly() {
  228. # Terminate already running bar instances
  229. killall -q polybar
  230. # Wait until the processes have been shut down
  231. while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
  232. cp -r $XDG_CONFIG_HOME/polybar/bars/polybar-$1/* $XDG_CONFIG_HOME/polybar/
  233. cp -r $XDG_CONFIG_HOME/polybar/fonts/* ~/.local/share/fonts
  234. fc-cache
  235. $XDG_CONFIG_HOME/polybar/launch.sh
  236. }
  237. vpn() {
  238. nmcli connect $1 $2.protonvpn.com.udp
  239. }
  240. define() {
  241. dict $1 | less;
  242. }
  243. n () {
  244. # Block nesting of nnn in subshells
  245. if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then
  246. echo "nnn is already running"
  247. return
  248. fi
  249. # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
  250. # To cd on quit only on ^G, remove the "export" as in:
  251. # NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
  252. # NOTE: NNN_TMPFILE is fixed, should not be modified
  253. NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
  254. # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
  255. # stty start undef
  256. # stty stop undef
  257. # stty lwrap undef
  258. # stty lnext undef
  259. nnn "$@"
  260. if [ -f "$NNN_TMPFILE" ]; then
  261. . "$NNN_TMPFILE"
  262. rm -f "$NNN_TMPFILE" > /dev/null
  263. fi
  264. }
  265. compare() {
  266. git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative $1..$2;
  267. }
  268. blaunch() {
  269. BASE16_SHELL="$HOME/.config/base16-shell/"
  270. [ -n "$PS1" ] && \
  271. [ -s "$BASE16_SHELL/profile_helper.sh" ] && \
  272. eval "$("$BASE16_SHELL/profile_helper.sh")"
  273. }