Dotfiles from time before I knew the word dotfiles, but the name has stuck.
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.

976 lines
31KB

  1. UNAME=$(uname)
  2. # TOC
  3. # Defaults etc... M0TZLS
  4. # Environment 7RS56S
  5. # Aliases RJ706I
  6. # Functions ZGC5QQ
  7. # enable terminal bell
  8. if [ -f /usr/bin/xset ];
  9. then
  10. (xset b on&)
  11. fi
  12. ##### Defaults etc... M0TZLS #####
  13. # ~/.bashrc: executed by bash(1) for non-login shells.
  14. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
  15. # for examples
  16. # If not running interactively, don't do anything
  17. [ -z "$PS1" ] && return
  18. # save history
  19. export PROMPT_COMMAND='history -a'
  20. # don't put duplicate lines in the history. See bash(1) for more options
  21. # ... or force ignoredups and ignorespace
  22. HISTCONTROL=ignoredups
  23. # append to the history file, don't overwrite it
  24. shopt -s histappend
  25. # check the window size after each command and, if necessary,
  26. # update the values of LINES and COLUMNS.
  27. shopt -s checkwinsize
  28. # make less more friendly for non-text input files, see lesspipe(1)
  29. [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  30. # set variable identifying the chroot you work in (used in the prompt below)
  31. if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  32. debian_chroot=$(cat /etc/debian_chroot)
  33. fi
  34. # set a fancy prompt (non-color, unless we know we "want" color)
  35. case "$TERM" in
  36. xterm-color) color_prompt=yes;;
  37. esac
  38. force_color_prompt=yes
  39. if [ -n "$force_color_prompt" ]; then
  40. if which tput >&/dev/null && tput setaf 1 >&/dev/null; then
  41. # We have color support; assume it's compliant with Ecma-48
  42. # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  43. # a case would tend to support setf rather than setaf.)
  44. color_prompt=yes
  45. else
  46. color_prompt=
  47. fi
  48. fi
  49. if [ "$color_prompt" = yes ]; then
  50. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  51. else
  52. PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  53. fi
  54. unset color_prompt force_color_prompt
  55. # Red colour for root, thanks nyuszika7h
  56. # Check if we're root
  57. if [[ $EUID == 0 ]]; then
  58. PS1='\033[1;31m\u@\h:\w\$\033[0m '
  59. else
  60. PS1='\033[1;32m\u@\h:\w\$\033[0m '
  61. fi
  62. # If this is an xterm set the title to user@host:dir
  63. case "$TERM" in
  64. xterm*|*rxvt*)
  65. PS1="\[\e]0;\u@\h: \w\a\]$PS1"
  66. ;;
  67. *)
  68. ;;
  69. esac
  70. # enable color support of ls and also add handy aliases
  71. if [ -x /usr/bin/dircolors ]; then
  72. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  73. alias ls='ls --color=always'
  74. alias dir='dir --color=always'
  75. alias vdir='vdir --color=always'
  76. alias grep='grep -i --color=always'
  77. alias fgrep='fgrep -i --color=always'
  78. alias egrep='egrep -i --color=always'
  79. fi
  80. # some more ls aliases
  81. if [[ $UNAME != Darwin ]]; then
  82. alias ll='ls -alFh --color=always' && alias la='ls -A --color=always' && alias l='ls -CF --color=always'
  83. fi
  84. if [[ $UNAME = Darwin ]]; then
  85. alias ls="ls -Gp"
  86. alias ll="ls -alFHGp"
  87. alias l="ls -CFGp"
  88. fi
  89. # Add an "alert" alias for long running commands. Use like so:
  90. # sleep 10; alert
  91. 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$//'\'')"'
  92. # Alias definitions.
  93. # You may want to put all your additions into a separate file like
  94. # ~/.bash_aliases, instead of adding them here directly.
  95. # See /usr/share/doc/bash-doc/examples in the bash-doc package.
  96. if [ -f ~/.bash_aliases ]; then
  97. . ~/.bash_aliases
  98. fi
  99. # enable programmable completion features (you don't need to enable
  100. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  101. # sources /etc/bash.bashrc).
  102. if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
  103. . /etc/bash_completion
  104. fi
  105. #Shopt settings.
  106. #shopt -s autocd
  107. # Show the hostname, uptime and users logged in on shell start
  108. (hostname&)
  109. (uptime&)
  110. (echo "")
  111. if [[ $UNAME != Darwin ]]; then
  112. (who -H -w -u|head -n10&)
  113. (echo "")
  114. # (last -10 -w -x&)
  115. fi
  116. if [[ $UNAME = Darwin ]]; then
  117. (who -H -u|head -n10&)
  118. (echo "")
  119. (last -10&)
  120. fi
  121. ##### Environment 7RS56S #####
  122. # Environment should be placed to .environment or .bash_environment.
  123. # Source before mentioned locations if they exist.
  124. # .environment
  125. if [ -f ~/.environment ]; then
  126. source ~/.environment
  127. fi
  128. # .bash_environment
  129. if [ -f ~/.bash_environment ]; then
  130. source ~/.bash_environment
  131. fi
  132. # Enable core files.
  133. (ulimit -c unlimited&)
  134. # More colours :D
  135. if [[ $TERM == 'xterm' ]]; then
  136. export TERM=xterm-256color
  137. fi
  138. if [[ $TERM == 'screen' ]]; then
  139. export TERM=screen-256color
  140. fi
  141. # Things after this are just examples and should be put to some other file, which is sourced above.
  142. # Sets the default editor. I am vim user, so I want it to be vim. If you don't like terminal based text editors, change "" to gedit (Gnome) or Kate (KDE).
  143. #export EDITOR=vim # MIKAELA_GREP MIKAELA_GREP_ENVIRONMENT
  144. # Sets locale. You can get list of locales with "locale -a" command. This
  145. # should be something which ends to .utf8
  146. #export LANG=fi_FI.UTF-8
  147. # Set TZ to local timezone for sending over SSH
  148. TZ=$(date +%Z)
  149. # Sets PATH. To add another path, add :</path/to/new/path> to string below.
  150. PATH=$HOME/.local/bin:$HOME/bin:$HOME/go/bin:$HOME/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/snap/bin:/usr/local/bin:/usr/local/sbin:/usr/local/games:/usr/bin:/usr/sbin:/usr/games:/bin:/sbin:/games:$PATH
  151. # Add RubyGems to PATH
  152. if hash ruby 2>/dev/null; then
  153. PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"
  154. fi
  155. # Removes duplicates from $PATH. Copied from http://unix.stackexchange.com/a/14896
  156. PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}')
  157. # "Changes" home directory without root. Uncomment both lines below this.
  158. #export HOME=<path to new home>
  159. #cd
  160. # Colours to less
  161. # Copied from http://nion.modprobe.de/blog/archives/572-less-colors-for-man-pages.html
  162. export LESS_TERMCAP_mb=$'\E[01;31m'
  163. export LESS_TERMCAP_md=$'\E[01;31m'
  164. export LESS_TERMCAP_me=$'\E[0m'
  165. export LESS_TERMCAP_se=$'\E[0m'
  166. export LESS_TERMCAP_so=$'\E[01;44;33m'
  167. export LESS_TERMCAP_ue=$'\E[0m'
  168. export LESS_TERMCAP_us=$'\E[01;32m'
  169. # Sets environment variable CPUARCH to output of "uname -p" & UNAME to "uname"
  170. UNAME=$(uname)
  171. CPUARCH=$(uname -p)
  172. # If we are on Linux, enable apt progress bar and colours
  173. # and Happy Eyeballs workaround https://pad.lv/1308200
  174. if [[ $USER = "root" ]]; then
  175. mkdir -p /etc/apt/apt.conf.d/
  176. echo 'Dpkg::Progress-Fancy "1";' > /etc/apt/apt.conf.d/99progressbar
  177. echo 'APT::Color "1";' > /etc/apt/apt.conf.d/99color
  178. # echo 'Acquire::http::Timeout "2";' > /etc/apt/apt.conf.d/99timeout
  179. # echo 'Acquire::ftp::Timeout "2";' >> /etc/apt/apt.conf.d/99timeout
  180. fi
  181. # Copied from http://homepages.see.leeds.ac.uk/~eeaol/notes/2012/03/how_to_only_type_ssh_passphrase_once/
  182. export SSH_AUTH_SOCK=/tmp/$USER.agent
  183. (ssh-agent -a /tmp/$USER.agent > /dev/null 2>&1&)
  184. # In our series useless/weird environment variables, beep
  185. export beep=
  186. export BEEP=
  187. # OS X ls colours (copied from https://apple.stackexchange.com/questions/33677/how-can-i-configure-mac-terminal-to-have-color-ls-output )
  188. export CLICOLOR=1
  189. export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
  190. # make
  191. alias maken="make -j$NPROC"
  192. # Ensure that pkg-config paths are found
  193. #export PKG_CONFIG_PATH=$(which pkg-config)
  194. # znc uses this variable for figuring out hostname
  195. export HOSTNAME=$(hostname --fqdn)
  196. ##### Aliases RJ706I #####
  197. # To get sudo work with aliases.
  198. alias sudo="sudo "
  199. # Moving between directories:
  200. alias ..="cd .."
  201. # Use htop instead of top, it's better. Requires htop.
  202. #alias top="htop" # MIKAELA_GREP # MIKAELA_GREP_ALIAS
  203. # Add title to youtube-dl & make yle-dl Windows-friendly
  204. alias youtube-dl="youtube-dl -o '%(title)s-%(id)s.%(ext)s'"
  205. alias yle-dl="yle-dl --vfat"
  206. # git specific. This is the command which I use when git asks me to commit something and says that I have modified files, even when I haven't.
  207. alias gdrop="git stash && git stash drop"
  208. # If I run nautilus, I want it to open in folder where I am.
  209. #alias nautilus="nautilus ./"
  210. #SHow compilation date of WeeChat.
  211. alias weechat-version="weechat --help|head -n2"
  212. #NMAP specific. All nmap things should be run as root, so it's probably best to copy these aliases to root's .bashrc. Things which don't run without root ask for sudo password.
  213. alias nmap-intense="nmap -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
  214. alias nmap-intense-udp="sudo nmap -sS -sU -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
  215. alias nmap-intense-all-tcp="nmap -p 1-65535 -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
  216. alias nmap-intense-no-ping="nmap -T4 -A -v -PN "
  217. alias nmap-ping="nmap -sP -PE -PA21,23,80,3389 "
  218. alias nmap-quick="nmap -T4 -F "
  219. alias nmap-quick-plus="sudo nmap -sV -T4 -O -F --version-light "
  220. alias nmap-traceroute="sudo nmap -sP -PE -PS22,25,80 -PA21,23,80,3389 -PU -PO --traceroute "
  221. alias nmap-regular="nmap "
  222. alias nmap-comprehensive="sudo nmap -sS -sU -T4 -A -v -PE -PP -PS21,22,23,25,80,113,31339 -PA80,113,443,10042 -PO --script all "
  223. # Little "safer" scan as connecting to only HTTP and HTTPS ports doesn't look so attacking. Copy-paste to .bash_custom and remove " -p 80,443" if you want to scan all ports which nmap scans by default.
  224. alias nmap-osscan="sudo nmap -p 80,443 -O -v --osscan-guess --fuzzy "
  225. # Downloads folder over SSH. Usage: rdownload <host>:<remotefolder> <local_destination> | TIP: use ~/ssh/config to configure hosts.
  226. alias rdownload="rsync -h --progress -avz "
  227. alias rscp='rsync -h --progress -avz '
  228. alias rscpr='rsync -h --progress -azvv '
  229. # TMUX specific
  230. alias tmux="tmux -2u"
  231. alias attach="tmux attach-session"
  232. alias detach="tmux detach"
  233. # I am always typoing "aptitude" with my phone...
  234. alias aptitute="aptitude "
  235. # The Battle for Wesnoth specific, http://wesnoth.org/
  236. # It seems to be an good idea to have debug logs on terminal with svn version.
  237. alias wesnoth="wesnoth --debug"
  238. # For copy-pasting directly from somewhere
  239. alias %=" "
  240. alias \#=" "
  241. # Supybot specifig. Why to write long command, if you can write short command?
  242. alias supybot-config-reload="killall -HUP supybot "
  243. alias supybot-owner-quit="killall -INT supybot "
  244. # Translating plugins in Limnoria
  245. alias supybot-generate-messages.pot="pygettext --docstrings config.py plugin.py"
  246. alias supybot-generate-messages.pot-xgettext="xgettext --language=Python config.py plugin.py && mv -f messages.po messages.pot"
  247. alias supybot-check-plugin-trans="sandbox/check_trans.py plugins/"
  248. alias supybot-check-core-trans="sandbox/check_trans.py --core"
  249. alias supybot-generate-messages.pot-mass="find . -type d -exec sh -c '(cd {} && pygettext --docstrings config.py plugin.py)' ';'"
  250. ## -- Start of aliases which are saved from Ubuntu default bashrc. --
  251. # enable color support of ls and also add handy aliases
  252. if [[ $UNAME != Darwin ]]; then
  253. alias ls='ls --color=always'
  254. fi
  255. # some more ls aliases
  256. if [[ $UNAME != Darwin ]]; then
  257. alias ll='ls -alFh --color=always' && alias la='ls -A --color=always' && alias l='ls -CF --color=always'
  258. fi
  259. ## -- End of aliases which are saved from Ubuntu default bashrc. --
  260. # Copying command in Supybot (Internet.DNS)
  261. alias dns="nslookup "
  262. alias dns6="nslookup -type=AAAA "
  263. alias nslookup6="nslookup -type=AAAA "
  264. # If I have nslookup6...
  265. alias dig6="dig AAAA "
  266. # SSHGuard specific
  267. alias sshguard-show-bans="sshguard4-show-bans && sshguard6-show-bans"
  268. alias sshguard4-show-bans="sudo iptables -L sshguard --line-numbers"
  269. alias sshguard6-show-bans="sudo ip6tables -L sshguard --line-numbers"
  270. # Enter ban number as arguement. You can see ban numbers with previous command.
  271. alias sshguard4-unban="sudo iptables -D sshguard "
  272. alias sshguard6-unban="sudo ip6tables -D sshguard "
  273. alias sshguard-unban-all="sshguard4-unban-all && sshguard-6-unban-all"
  274. alias sshguard4-unban-all="sudo iptables -F sshguard"
  275. alias sshguard6-unban-all="sudo ip6tables -F sshguard"
  276. # This needs something which makes it easy to remember.
  277. alias KILL="killall -KILL "
  278. # For locally rsync copying folder1 to folder2.
  279. alias rsync-folder="rsync -h --progress -azvv "
  280. # SSHGuard seems to prefer users to run this always when connecting with keys in ssh-agent...
  281. if [[ $UNAME != Darwin ]]; then
  282. alias ssh-add="\ssh-add -D && \ssh-add "
  283. fi
  284. # Use GPG2 instead of GPG!
  285. alias gpg=gpg2
  286. export KEYBASE_GPG=gpg2
  287. alias gpg-fix-tty='export GPG_TTY=$(tty)'
  288. # For userspecific installation of mosh on remote server.
  289. alias lmosh="mosh --server=~/.local/bin/mosh-server "
  290. alias lmosha="mosh --server=~/.local/bin/mosh-server-alt "
  291. # Secure cat
  292. alias scat="gpg --decrypt "
  293. # To check are keys, which apt uses changed
  294. #alias apt-key-refresh-keys="apt-key adv --keyserver hkps://keys.openpgp.org --refresh-keys"
  295. # To see which mirror httpredir.debian.org puts you to. The file which has the latest update time is the mirror which you are using.
  296. alias httpredir.debian.org="curl -sL http://httpredir.debian.org/debian/project/trace/|pandoc -f html -t markdown"
  297. # Amount of keys in GPG keyring.
  298. alias gpg-key-amount="gpg --list-keys|grep '^pub'|wc -l"
  299. alias gpg-key-count="gpg --export -a|gpg --import"
  300. alias follow="tail -F"
  301. # Current IPv4 and IPv6 addresses. Calls functions.
  302. alias myip="myip4 && myip6"
  303. # Update groups without logging out. Requires entering password. Source: http://blog.edwards-research.com/2010/10/linux-refresh-group-membership-without-logging-out/
  304. alias refreshgroups="exec su -l $USER"
  305. # Get public key lenght of (public) SSH key
  306. alias ssh-pubkey-length="ssh-keygen -lf "
  307. # MSDOS commands. MSDOS is after every alias line to get these lines easily by grepping.
  308. alias cls=clear # MSDOS
  309. alias help=man # MSDOS
  310. alias ipconfig=ifconfig # MSDOS
  311. alias copy=cp # MSDOS
  312. alias move=mv # MSDOS
  313. # List git committers of repository
  314. alias git-committers="git shortlog -s"
  315. alias git-changelog="git log --oneline --decorate"
  316. alias git-changelog-color="git log --oneline --decorate --color"
  317. # Line ending converting with flip
  318. alias unixle="flip -ub "
  319. alias msdosle="flip -mb "
  320. # Making .iso bootable from CD/DVD/USB. Cat it to /dev/<DEVICE>
  321. # MaKe Hybrid ISO
  322. alias mkhiso=isohybrid
  323. # Yum
  324. alias yum-unlock="rm -rf /var/run/yum.pid"
  325. alias yum-rm-timedhosts="rm /var/cache/yum/$CPUARCH/17/timedhost*"
  326. alias yummy="yum -y "
  327. alias yummn="yum -n "
  328. alias yumy=yummy
  329. alias yumn=yummn
  330. # Archiving and extracting with tar
  331. # This is tartar to avoid conflict with tar
  332. alias tartar="tar cfv "
  333. alias targz="tar cfvz "
  334. alias tarbz2="tar cfvj "
  335. # I have function ex so these are ex-* to avoid conflict.
  336. # ex-tartar and ex-tar, because there is alias tartar and command tar
  337. alias ex-tar="tar xfv "
  338. alias ex-tartar="tar xfv "
  339. alias ex-targz="tar xfvz "
  340. alias ex-tarbz2="tar xfvj "
  341. # To have less handle ls colours
  342. alias less="less -R "
  343. # "su -" with/without sudo
  344. alias ssu="sudo su -"
  345. alias suu="su -"
  346. # systemd runlevels/targets
  347. alias currenttargets="systemctl list-units --type=target"
  348. alias telsystemd="systemctl isolate "
  349. alias defaulttarget="systemctl enable "
  350. # Fedora Utils http://satya164.github.com/fedorautils/
  351. alias fedorautils="\fedorautils -c"
  352. alias fedorautils-install='su -c "curl http://download.opensuse.org/repositories/home:/satya164:/fedorautils/Fedora_17/home:satya164:fedorautils.repo -Lo /etc/yum.repos.d/fedorautils.repo && yum -y install fedorautils"'
  353. # ReSet Screen rss
  354. alias rss=reset
  355. # Who command which I use with Conky
  356. alias cwho="who -H -w -u"
  357. # Upgrading Redhat/Debian
  358. alias yumyup="yum -y check-update;yum -y update;grub2-mkconfig -o /boot/grub2/grub.cfg"
  359. alias apt-getyup="apt-get -y update;apt-get -y upgrade;update-grub"
  360. alias aptitudeyup="aptitude -y update;aptitude -y upgrade;update-grub"
  361. alias aptyup="apt -y update;apt -y upgrade;update-grub"
  362. alias apty="apt -y"
  363. alias apt-gety="apt-get -y "
  364. alias aptitudey="aptitude -y "
  365. # inxi https://code.google.com/p/inxi/
  366. alias inxi-install="mkdir -p ~/.local/bin && cd ~/.local/bin && \wget -Nc smxi.org/inxi && chmod +x inxi && cd"
  367. alias inxi-install-root="cd /usr/local/bin;\wget -Nc smxi.org/inxi;chmod +x inxi;./inxi -U;cd"
  368. alias inxi-update="inxi -U"
  369. # FINEID
  370. #alias ssh-add-sc="ssh-add -s $(find /usr/*lib -name 'opensc-pkcs11.so')"
  371. alias ssh-add-sc-pub="\ssh-add -L"
  372. ## apt in Ubuntu 14.04+ and other distributions
  373. #if [ -f /usr/bin/apt ]; then
  374. # alias aptitude=apt
  375. # alias apt-get=apt
  376. # alias apt-cache=apt
  377. #fi
  378. # Same as the previous, but for yum --> dnf
  379. if [ -f /usr/bin/dnf ]; then
  380. alias yum=dnf
  381. fi
  382. # Homebrew
  383. alias homebrew-install="cd ~;git clone https://github.com/Homebrew/homebrew.git --depth=1;mkdir -p .local;rsync -aP homebrew/* .local;rsync -aP homebrew/.* .local;rm -rf homebrew"
  384. alias homebrew-install-root="cd /usr;git clone https://github.com/Homebrew/homebrew.git --depth=1;mkdir -p local;rsync -aP homebrew/* local;rsync -aP homebrew/.* local/;chmod -R 755 local;chown -R root:wheel local;rm -rf homebrew"
  385. alias linuxbrew-install="cd ~;git clone https://github.com/Homebrew/linuxbrew.git --depth=1;mkdir -p .local;rsync -aP linuxbrew/* .local;rsync -aP linuxbrew/.* .local;rm -rf linuxbrew"
  386. alias linuxbrew-install-root="cd /usr;git clone https://github.com/Homebrew/linuxbrew.git --depth=1;mkdir -p local;rsync -aP linuxbrew/* local;rsync -aP linuxbrew/.* local/;chmod -R 755 local;chown -R root:wheel local;rm -rf linuxbrew"
  387. export HOMEBREW_LOGS=$HOME/.cache/Homebrew/Logs
  388. # OS X
  389. alias osx-server-caching-interface="serveradmin settings caching:Interface ="
  390. alias osx-show-hidden-files="defaults write com.apple.finder AppleShowAllFiles"
  391. alias osx-airdrop-listenallif="defaults write com.apple.NetworkBrowser BrowseAllInterfaces"
  392. alias osx-set-updatecheck="defaults write /Library/Preferences/com.apple.SoftwareUpdate ScheduleFrequency"
  393. # Simple HTTPd with Python.
  394. alias python2-httpd="python2 -m SimpleHTTPServer"
  395. alias python3-httpd="python3 -m http.server"
  396. # Resetting different desktop environments
  397. alias reset-gnome="rm -rf ~/.gnome ~/.gnome2 ~/.gconf ~/.gconfd ~/.metacity ~/.cache ~/.dbus ~/.dmrc ~/.mission-control ~/.thumbnails ~/.config/dconf/user ~/.compiz*"
  398. alias reset-unity="unity-tweak-tool --reset-unity"
  399. alias reset-kde="rm -rf ~/.kde4 ~/.kde"
  400. alias reset-lxpanel="rm -rf ~/.config/lxpanel;lxpanelctl restart"
  401. alias reset-xfce4="rm -rf ~/.config/xfce4"
  402. alias reset-matepanel="mate-panel --reset"
  403. # Show date in ISO 8601 format
  404. alias isodate='date -Is'
  405. alias isodateu='date -uIs'
  406. alias isodatea='date "+%Y-%m-%dT%H:%M:%S%z"'
  407. alias isodateua='date -u "+%Y-%m-%dT%H:%M:%S%z"'
  408. # Show information on PEM file.
  409. alias peminfo="openssl x509 -text -in"
  410. # tmux emergency attach
  411. alias tmuxeattach="/proc/$(pgrep -o tmux)/exe attach"
  412. # Reset configuration files on systems using apt
  413. alias purgeconfig="apt-get install --reinstall -o DPkg::options::=--force-confask"
  414. # Send command output to sprunge.us or ix.io `command|<sprungeus|ixio>`
  415. alias sprungeus="curl -F 'sprunge=<-' http://sprunge.us"
  416. alias ixio="curl -F 'f:1=<-' ix.io"
  417. # Copy-paste mtr output more easily
  418. alias mtrp4="mtr -rw4c 10"
  419. alias mtrp6="mtr -rw6c 10"
  420. # pip
  421. alias pip="python -m pip"
  422. alias pip2="python2 -m pip"
  423. alias pip3="python3 -m pip"
  424. alias pippypy="pypy -m pip"
  425. alias pippypy2="pypy2 -m pip"
  426. alias pippypy3="pypy3 -m pip"
  427. alias pypypip=pippypy
  428. alias pypypip2=pippypy2
  429. alias pypypip3=pippypy3
  430. # apg with small letters, capital letters and numbers. I don't usually use
  431. # special characters as they sometimes have difficulties with some systems
  432. # and cross-platform operating systems.
  433. # APG IS LIMITED TO 255 CHARACTERS SO IT'S REPLACED WITH PWGEN!
  434. # Usage: apt-random <minimum length>
  435. alias apg-random="pwgen -sy"
  436. # cp/mv using rsync. rcp appears to be link to scp in my system, so I can
  437. # safely use this alias.
  438. alias rcp="rsync -a --progress"
  439. alias rmv="rsync -a --progress --remove-source-files"
  440. # Clear apt list cache
  441. alias clear-apt-list-cache="cd /var/lib/apt/lists && rm -f *|true && cd partial && rm -f *|true && cd"
  442. # Accept all cookies with Lynx, makes browsing easier and
  443. # every other browser does this too.
  444. alias lynx="lynx -accept_all_cookies"
  445. # Cat multiple files preserving filenames
  446. # via http://stackoverflow.com/a/7816490
  447. alias multicat='tail -n +1'
  448. # Getting SSIDs and keys from connmann (Jolla)
  449. alias connman-wlans='grep -E "Name|Passphrase" /var/lib/connman/wifi*/settings --no-filename'
  450. # Turn input into lowercase and remove colons.
  451. # Meant for SSL certificates (IRC))
  452. alias lowernocolon="tr -d ':' | tr 'A-Z' 'a-z'"
  453. # As pacman and yay share the same flags
  454. #if hash yay 2>/dev/null; then
  455. # alias pacman="LANG=en yay --needed"
  456. #else
  457. # I don't want to reinstall exact same versions that I have
  458. alias pacman="LANG=en pacman --needed"
  459. #fi
  460. # Sailfish Network status, via IRC
  461. alias sailfish-nstatus='dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Manager.GetServices|less'
  462. # apt build depedencies (without installing)
  463. alias apt-builddep="apt-rdepends --build-depends --follow=DEPENDS"
  464. # http://superuser.com/a/638033 - get embedded Windows key
  465. alias winkey="xxd /sys/firmware/acpi/tables/MSDM"
  466. # Always exec startx so Ctrl-Alt-Backspace won't lead to unlocked TTY.
  467. alias startx="exec \startx"
  468. # cat list of kernel detected vulnerabilities/states with filenames
  469. alias linux-check-cpu-vulns="tail -n +1 /sys/devices/system/cpu/vulnerabilities/*"
  470. # Allow custom aliases to be put in .aliases or .bash_aliases .
  471. # .aliases
  472. if [ -f ~/.aliases ]; then
  473. source ~/.aliases
  474. fi
  475. # .bash_aliases
  476. if [ -f ~/.bash_aliases ]; then
  477. source ~/.bash_aliases
  478. fi
  479. ##### Functions ZGC5QQ #####
  480. # GEOIP lookup, improved from the ultimate bashrc http://goo.gl/qGK5j
  481. function geoip() {
  482. geoiplookup $1
  483. geoiplookup6 $1
  484. }
  485. # Checks which package the command comes from. Copied from the ultimate bashrc http://goo.gl/qGK5j
  486. function cmdpkg() { PACKAGE=$(dpkg -S $(which $1) | cut -d':' -f1); echo "[${PACKAGE}]"; dpkg -s "${PACKAGE}" ;}
  487. # Down for everyone or just me? Copied from the ultimate bashrc http://goo.gl/qGK5j
  488. function downforme() {
  489. RED='\e[1;31m'
  490. GREEN='\e[1;32m'
  491. YELLOW='\e[1;33m'
  492. NC='\e[0m'
  493. if [ $# = 0 ]
  494. then
  495. echo -e "${YELLOW}usage:${NC} downforme website_url"
  496. else
  497. JUSTYOUARRAY=($(lynx -dump http://downforeveryoneorjustme.com/$1 | grep -o "It's just you"))
  498. if [ ${#JUSTYOUARRAY} != 0 ]
  499. then
  500. echo -e "${RED}It's just you. \n${NC}$1 is up."
  501. else
  502. echo -e "${GREEN}It's not just you! \n${NC}$1 looks down from here."
  503. fi
  504. fi
  505. }
  506. # Topt10 commands, copied from the ultimate bashrc http://goo.gl/qGK5j
  507. function top10() {
  508. # copyright 2007 - 2010 Christopher Bratusek
  509. \history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head
  510. }
  511. # ex command. Copied from bashrc of bioterror ( http://ricecows.org/configs/bash/.bashrc ). Original comment below:
  512. ## for unit193 ;)
  513. ## use command "ex" to extract any archive files.
  514. ## "ex package.zip" for example
  515. function ex ()
  516. {
  517. if [ -f "$1" ] ; then
  518. case "$1" in
  519. *.tar) tar xvf $1 ;;
  520. *.tar.bz2 | *.tbz2 ) tar xjvf $1 ;;
  521. *.tar.gz | *.tgz ) tar xzvf $1 ;;
  522. *.bz2) bunzip2 $1 ;;
  523. *.rar) unrar x $1 ;;
  524. *.gz) gunzip $1 ;;
  525. *.zip) unzip $1 ;;
  526. *.Z) uncompress $1 ;;
  527. *.7z) 7z x $1 ;;
  528. *.xz) tar xJvf $1 ;;
  529. *.deb)
  530. DIR=${1%%_*.deb}
  531. ar xv $1
  532. mkdir ${DIR}
  533. tar -C ${DIR} -xzvf data.tar.gz ;;
  534. *.rpm) rpm2cpio $1 | cpio -vid ;;
  535. *) echo ""${1}" cannot be extracted via extract()"
  536. ;;
  537. esac
  538. else
  539. echo ""${1}" is not a valid file"
  540. fi
  541. }
  542. # Given by nyuszika7h. Shortens GitHub URLs with git.io
  543. function gitio() {
  544. curl -s -i http://git.io -F "url=$1" | grep --color=never -P '^Location: ' | awk '{ print $2 }'
  545. }
  546. function mkcd() {
  547. if [[ $# -gt 1 ]]; then
  548. echo 'Warning: All directories will be created, but will change to first specified directory.' 1>&2
  549. fi
  550. mkdir -p "$*" && cd "$1"
  551. }
  552. function gribble-gpg-everify() {
  553. # Set which command to use for gpg. You
  554. # probably want to use gpg2 here.
  555. local gpg=gpg2
  556. echo -n 'Enter Bitcoin OTC URL: '
  557. read REPLY
  558. lynx -hiddenlinks=ignore -dump $REPLY > bitcoin_otc.txt.asc
  559. $gpg --decrypt-file bitcoin_otc.txt.asc
  560. echo -en '\e[1;32m;;everify '
  561. cat bitcoin_otc.txt
  562. echo -e '\e[0m'
  563. rm -rf bitcoin_otc.txt bitcoin_otc.txt.asc
  564. }
  565. # This function will install/upgrade shell-things.
  566. function shell-things {
  567. export SHELL_THINGS_REPO=$HOME/.shell-things
  568. # Check if ~/.shell-things exists and cd and pull.
  569. if [ -d $SHELL_THINGS_REPO ]; then
  570. echo "shell-things: $SHELL_THINGS_REPO exists, git pulling..."
  571. echo ""
  572. cd $SHELL_THINGS_REPO
  573. git remote set-url origin https://gitea.blesmrt.net/Mikaela/shell-things.git
  574. git pull
  575. echo ""
  576. echo "shell-things: Installing/Upgrading..."
  577. echo ""
  578. # If it doesn't exist...
  579. else
  580. echo ""
  581. echo "shell-things: $SHELL_THINGS_REPO doesn't exist, cloning..."
  582. echo ""
  583. git clone https://gitea.blesmrt.net/Mikaela/shell-things.git $SHELL_THINGS_REPO
  584. cd $SHELL_THINGS_REPO
  585. echo ""
  586. echo "shell-things: Installing/Upgrading..."
  587. echo ""
  588. fi
  589. # Installing...
  590. bash -x ./install
  591. echo ""
  592. echo "shell-things: Everthing is now done :)"
  593. echo ""
  594. cd
  595. }
  596. # This function will download and install sources.list.
  597. function sources-list-install {
  598. export RELEASE=$(lsb_release -sr)
  599. a[1]="https://raw.githubusercontent.com/Mikaela/shell-things/master/etc/apt/sources.list/$RELEASE"
  600. echo "I am now changing directory to /etc/apt/."
  601. echo ""
  602. cd /etc/apt/
  603. echo "I will now backup sources.list to sources.list.bak ."
  604. echo ""
  605. cp /etc/apt/sources.list /etc/apt/sources.list.bak
  606. echo "I will now download the sources.list file from https://raw.githubusercontent.com/Mikaela/shell-things/master/etc/apt/sources.list/$RELEASE and save it as /etc/apt/sources.list ."
  607. echo ""
  608. echo "" > /etc/apt/sources.list
  609. \wget ${a[1]} -O /etc/apt/sources.list
  610. #\curl -L ${a[1]} >> /etc/apt/sources.list
  611. echo ""
  612. echo "The new sources.list file should now be installed."
  613. echo ""
  614. echo "Finally, I will now run 'apt-get -y update' so the new sources.list is used."
  615. echo ""
  616. apt-get update
  617. echo "I have now finished everything that I was supposed to do."
  618. }
  619. # Same for Debian (codename instead of release)
  620. function sources-list-install-debian {
  621. export RELEASE=$(lsb_release -sc)
  622. a[1]="https://raw.githubusercontent.com/Mikaela/shell-things/master/etc/apt/sources.list/$RELEASE"
  623. echo "I am now changing directory to /etc/apt/."
  624. echo ""
  625. cd /etc/apt/
  626. echo "I will now backup sources.list to sources.list.bak ."
  627. echo ""
  628. cp /etc/apt/sources.list /etc/apt/sources.list.bak
  629. echo "I will now download the sources.list file from https://raw.githubusercontent.com/Mikaela/shell-things/master/etc/apt/sources.list/$RELEASE and save it as /etc/apt/sources.list ."
  630. echo ""
  631. echo "" > /etc/apt/sources.list
  632. \wget ${a[1]} -O /etc/apt/sources.list
  633. #\curl -L ${a[1]} >> /etc/apt/sources.list
  634. echo ""
  635. echo "The new sources.list file should now be installed."
  636. echo ""
  637. echo "Finally, I will now run 'apt-get -y update' so the new sources.list is used."
  638. echo ""
  639. apt-get update
  640. echo "I have now finished everything that I was supposed to do."
  641. }
  642. # This function fixes nodejs on Debian based systems.
  643. # (Everything expects nodejs to be called as node, but it's not with Debian.)
  644. fix-node () {
  645. if [[ $USER = "root" && -f /usr/bin/nodejs && ! -f /usr/bin/node && ! -f /usr/local/bin/node ]]
  646. then
  647. ln -s /usr/bin/nodejs /usr/local/bin/node
  648. fi
  649. mkdir -p $HOME/.local/bin
  650. if [[ -f /usr/bin/nodejs && ! -f /usr/bin/node && ! -f /usr/local/bin/node && ! -f $HOME/.local/bin/node ]]
  651. then
  652. ln -s /usr/bin/nodejs $HOME/.local/bin/node
  653. fi
  654. }
  655. # This function fixes automatic startup in graphical sessions.
  656. # I have had issues with auto start not doing anything and this seems to
  657. # fix it.
  658. fix-autostart() {
  659. if [[ $USER = "root" ]]
  660. then
  661. mkdir -p /etc/xdg/autostart
  662. chmod -R 755 /etc/xdg/autostart
  663. fi
  664. mkdir -p ~/.config/autostart
  665. chmod -R 755 ~/.config/autostart
  666. }
  667. # This function removes and regenerates ssh host keys.
  668. ssh-regen-host-keys () {
  669. rm /etc/ssh/ssh_host_*
  670. ssh-keygen -t dsa -N "" -f /etc/ssh/ssh_host_dsa_key
  671. ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key
  672. ssh-keygen -t ecdsa -N "" -f /etc/ssh/ssh_host_ecdsa_key
  673. ssh-keygen -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key
  674. }
  675. # This function erases Master Boot Record from device
  676. # Note: this is dangerous so this function will echo the command
  677. # instad of running it!
  678. erase-mbr() {
  679. echo dd if=/dev/zero of=$1 bs=512 count=2
  680. }
  681. # Use clang if installed. It seems interesting and this is probably good
  682. # way to test it. This might not be a function, but I don't have any better
  683. # place for this.
  684. if hash clang 2>/dev/null; then
  685. export CC=clang
  686. export HOMEBREW_CC=clang
  687. fi
  688. if hash clang++ 2>/dev/null; then
  689. export CXX=clang++
  690. fi
  691. # Add GitHub pull requests to fetched things via http://git.io/-C-0oQ
  692. github-add-pulls() {
  693. git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
  694. git config --add remote.upstream.fetch '+refs/pull/*/head:refs/remotes/upstream/-pr/*'
  695. }
  696. # Get server SSL certificate fingerprint in MD5, SHA1 and SHA256.
  697. # Note that OpenSSL doesn't support IPv6 at time of writing (2015-01-13).
  698. serversslcertfp () {
  699. SSSLCFFN=$(openssl s_client -showcerts -connect $1 < /dev/null)
  700. # To see all validity information
  701. echo "$SSSLCFFN"
  702. # For getting the fingerprints
  703. echo "$SSSLCFFN" | openssl x509 -md5 -fingerprint -noout
  704. echo "$SSSLCFFN" | openssl x509 -sha1 -fingerprint -noout
  705. echo "$SSSLCFFN" | openssl x509 -sha256 -fingerprint -noout
  706. echo "$SSSLCFFN" | openssl x509 -sha512 -fingerprint -noout
  707. unset SSSLCFFN
  708. }
  709. # The same for local certificate file
  710. sslcertfp () {
  711. cat $1 | openssl x509 -md5 -fingerprint -noout
  712. cat $1 | openssl x509 -sha1 -fingerprint -noout
  713. cat $1 | openssl x509 -sha256 -fingerprint -noout
  714. cat $1 | openssl x509 -sha512 -fingerprint -noout
  715. }
  716. # Usage: serversslciphers hostname port
  717. serversslciphers() {
  718. nmap -Pn $1 -p $2 --script +ssl-enum-ciphers
  719. }
  720. # Generate SSL certificate
  721. sslgenpem () {
  722. openssl req -nodes -newkey rsa:4096 -keyout $1.pem -x509 -days 3650 -out $1.pem -subj "/CN=$2"
  723. }
  724. # Managing SSL certificates of Google Chrome
  725. chrome-add-cert () {
  726. echo "Please ensure that either libnss3-tools or nss-tools is installed."
  727. certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n $1 -i $1
  728. }
  729. chrome-list-certs () {
  730. echo "Please ensure that either libnss3-tools or nss-tools is installed."
  731. certutil -d sql:$HOME/.pki/nssdb -L # add '-h all' to see all built-in certs
  732. }
  733. ssldownloadcert () {
  734. echo "Please ensure that either libnss3-tools or nss-tools is installed."
  735. echo QUIT | openssl s_client -connect $1:443 | sed -ne '/BEGIN CERT/,/END CERT/p' | tee $1.pem
  736. }
  737. # Getting magnet from transmission-daemon
  738. transmission-torrents () {
  739. transmission-remote -l
  740. }
  741. transmission-magnet () {
  742. transmission-remote -l -t $1 -i | grep magnet
  743. }
  744. # Merges the last $1 commits into one
  745. git-squash () {
  746. git reset --soft HEAD~$1
  747. git commit
  748. }
  749. # Combining mtrp4 & mtp6
  750. mtrp() {
  751. mtrp4 $@
  752. mtrp6 $@
  753. }
  754. # My IPv4 address
  755. myip4 () {
  756. if hash dig 2>/dev/null; then
  757. dig +short myip.opendns.com. A @208.67.222.222
  758. else
  759. curl -L4s http://icanhazip.com/
  760. fi
  761. }
  762. # My IPv6 address
  763. myip6 () {
  764. if hash dig 2>/dev/null; then
  765. dig +short myip.opendns.com. AAAA @2620:0:ccc::2
  766. else
  767. curl -L6s http://icanhazip.com/
  768. fi
  769. }
  770. # acme.sh
  771. if [ -f ~/.acme.sh/acme.sh.env ]; then
  772. source ~/.acme.sh/acme.sh.env
  773. fi
  774. # .custom
  775. if [ -f ~/.custom ]; then
  776. source ~/.custom
  777. fi
  778. # .bash_custom
  779. if [ -f ~/.bash_custom ]; then
  780. source ~/.bash_custom
  781. fi