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.

972 lines
31KB

  1. # TOC
  2. # Defaults etc... M0TZLS
  3. # Environment 7RS56S
  4. # Aliases RJ706I
  5. # Functions ZGC5QQ
  6. # uname should be readable in $uname
  7. uname=$(uname)
  8. UNAME=$(uname)
  9. # Dynamic window title via https://stackoverflow.com/a/20772424
  10. ## BREAKS TMUX TITLE CHANGING WHICH IS BETTER THAN THIS.
  11. #case $TERM in
  12. # (*xterm* | *rxvt*)
  13. # Write some info to terminal title.
  14. # This is seen when the shell prompts for input.
  15. # function precmd {
  16. # print -Pn "\e]0;zsh%L %(1j,%j job%(2j|s|); ,)%~\a"
  17. # }
  18. # Write command and args to terminal title.
  19. # This is seen while the shell waits for a command to complete.
  20. # function preexec {
  21. # printf "\033]0;%s\a" "$1"
  22. # }
  23. #
  24. # ;;
  25. #esac
  26. # enable terminal bell
  27. if [[ -f /usr/bin/xset ]];
  28. then
  29. (xset b on&)
  30. fi
  31. ##### Defaults etc... M0TZLS #####
  32. # This is based on zshrc which came with Debian (Third option in wizard for new users.)
  33. # Save history
  34. export HISTSIZE=99999
  35. export SAVEHIST=$HISTSIZE
  36. setopt hist_ignore_all_dups
  37. export HISTFILE=~/.zsh_history
  38. setopt INC_APPEND_HISTORY
  39. setopt SHARE_HISTORY
  40. # Set up the prompt
  41. autoload -Uz promptinit
  42. # Green for normal user and red for root and show exit status
  43. # if it's not 0. Thank you nyuszika7h
  44. promptinit
  45. #autoload -Uz vcs_info
  46. autoload -Uz colors && colors
  47. setopt PROMPT_SUBST
  48. #zstyle ':vcs_info:*' check-for-changes true
  49. #zstyle ':vcs_info:*' enable git svn bzr hg
  50. #zstyle ':vcs_info:*' formats '%b '
  51. #precmd() { vcs_info }
  52. PS1="%B%(!.%F{red}.%F{green})%n@%m %~
  53. %# %(?..%B%?%b )%f%b"
  54. # Use emacs keybindings even if our EDITOR is set to vi
  55. bindkey -e
  56. # Use modern completion system
  57. autoload -Uz compinit
  58. compinit
  59. zstyle ':completion:*' auto-description 'specify: %d'
  60. zstyle ':completion:*' completer _expand _complete _correct _approximate
  61. zstyle ':completion:*' format 'Completing %d'
  62. zstyle ':completion:*' group-name ''
  63. zstyle ':completion:*' menu select=2
  64. if [[ $UNAME != Darwin ]]; then
  65. eval "$(dircolors -b)"
  66. fi
  67. zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
  68. zstyle ':completion:*' list-colors ''
  69. zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
  70. zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
  71. zstyle ':completion:*' menu select=long
  72. zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
  73. zstyle ':completion:*' use-compctl false
  74. zstyle ':completion:*' verbose true
  75. zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
  76. zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
  77. # Show the hostname, uptime and users logged in on shell start
  78. (hostname&)
  79. (uptime&)
  80. (echo "")
  81. if [[ $UNAME != Darwin ]] then;
  82. (who -H -w -u|head -n10&)
  83. (echo "")
  84. # (last -10 -w -x&)
  85. fi
  86. if [[ $UNAME = Darwin ]]; then
  87. (who -H -u|head -n10&)
  88. (echo "")
  89. (last -10&)
  90. fi
  91. ##### Environment 7RS56S #####
  92. # Environment should be placed to .environment or .zsh_environment (or .zshenv).
  93. # Source before mentioned locations if they exist.
  94. # .environment
  95. if [ -f ~/.environment ]; then
  96. source ~/.environment
  97. fi
  98. # .zsh_environment
  99. if [ -f ~/.zsh_environment ]; then
  100. source ~/.zsh_environment
  101. fi
  102. # .zshenv (Yes, I know that this is sourced by every zsh session even if this isn't here, but I just want to write it).
  103. if [ -f ~/.zshenv ]; then
  104. source ~/.zshenv
  105. fi
  106. # Enable core files.
  107. (ulimit -c unlimited&)
  108. #More colours
  109. if [[ $TERM == 'xterm' ]]; then
  110. export TERM=xterm-256color
  111. fi
  112. if [[ $TERM == 'screen' ]]; then
  113. export TERM=screen-256color
  114. fi
  115. # Sets the default editor.
  116. #export EDITOR=vim # MIKAELA_GREP # MIKAELA_GREP_ENVIRONMENT
  117. # Sets locale. You can get list of locales with "locale -a" command. This should be something which ends to .utf8
  118. #export LANG=fi_FI.UTF-8 # MIKAELA_GREP # MIKAELA_GREP_ENVIRONMENT
  119. # Sets your timezone. Set in format <Region/City>, or just timezone like UTC.
  120. # export TZ="Europe/Helsinki" # MIKAELA_GREP # MIKAELA_GREP_ENVIRONMENT
  121. # Sets PATH. To add another path, add :</path/to/new/path> to string below.
  122. PATH=$HOME/.local/bin:$HOME/.local/sbin:$HOME/.local/games:$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin:$HOME/.linuxbrew/games:$HOME/bin:$HOME/sbin:$HOME/games:/usr/local/bin:/usr/local/sbin:/usr/local/games:/usr/bin:/usr/sbin:/usr/games:/bin:/sbin:/games:$PATH
  123. # Add RubyGems to PATH
  124. if hash ruby 2>/dev/null; then
  125. PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"
  126. fi
  127. # Removes duplicates from $PATH. Copied from http://unix.stackexchange.com/a/14896
  128. PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}')
  129. # "Changes" home directory without root. Uncomment both lines below this.
  130. #export HOME=<path to new home>
  131. #cd
  132. # Colours to less
  133. # Copied from http://nion.modprobe.de/blog/archives/572-less-colors-for-man-pages.html
  134. export LESS_TERMCAP_mb=$'\E[01;31m'
  135. export LESS_TERMCAP_md=$'\E[01;31m'
  136. export LESS_TERMCAP_me=$'\E[0m'
  137. export LESS_TERMCAP_se=$'\E[0m'
  138. export LESS_TERMCAP_so=$'\E[01;44;33m'
  139. export LESS_TERMCAP_ue=$'\E[0m'
  140. export LESS_TERMCAP_us=$'\E[01;32m'
  141. # Sets environment variable CPUARCH to output of "uname -p" and UNAME to "uname"
  142. CPUARCH=$(uname -p)
  143. # Copied from http://homepages.see.leeds.ac.uk/~eeaol/notes/2012/03/how_to_only_type_ssh_passphrase_once/
  144. export SSH_AUTH_SOCK=/tmp/$USER.agent
  145. ssh-agent -a /tmp/$USER.agent > /dev/null 2>&1
  146. # If we are on Linux, enable apt progress bar and colours
  147. # and Happy Eyeballs workaround https://pad.lv/1308200
  148. if [[ $USER = "root" ]]; then
  149. mkdir -p /etc/apt/apt.conf.d/
  150. echo 'Dpkg::Progress-Fancy "1";' > /etc/apt/apt.conf.d/99progressbar
  151. echo 'APT::Color "1";' > /etc/apt/apt.conf.d/99color
  152. echo 'Acquire::http::Timeout "2";' > /etc/apt/apt.conf.d/99timeout
  153. echo 'Acquire::ftp::Timeout "2";' >> /etc/apt/apt.conf.d/99timeout
  154. fi
  155. # In our series useless/weird environment variables, beep
  156. export beep=
  157. export BEEP=
  158. # OS X ls colours (copied from https://apple.stackexchange.com/questions/33677/
  159. export CLICOLOR=1
  160. export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
  161. # make
  162. alias maken="make -j$NPROC"
  163. # Ensure that pkg-config paths are found
  164. #export PKG_CONFIG_PATH=$(which pkg-config)
  165. # znc uses this variable for figuring out hostname
  166. export HOSTNAME=$(hostname --fqdn)
  167. ##### Aliases RJ706I #####
  168. # To get sudo work with aliases.
  169. alias sudo="sudo "
  170. # Moving between directories:
  171. alias ..="cd .."
  172. # Use htop instead of top, it's better. Requires htop.
  173. #alias top="htop" # MIKAELA_GREP MIKAELA_GREP_ALIAS
  174. # Add title to youtube-dl & make yle-dl Windows-friendly
  175. alias youtube-dl="youtube-dl -t"
  176. alias yle-dl="yle-dl --vfat"
  177. # 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.
  178. alias gdrop="git stash && git stash drop"
  179. # Show compilation date of WeeChat.
  180. alias weechat-version="weechat --help|head -n2"
  181. #NMAP specific. All nmap things should be run as root, so it's probably best to copy these aliases to root's .zshrc. Things which don't run without root ask for sudo password.
  182. alias nmap-intense="nmap -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
  183. alias nmap-intense-udp="sudo nmap -sS -sU -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
  184. alias nmap-intense-all-tcp="nmap -p 1-65535 -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 "
  185. alias nmap-intense-no-ping="nmap -T4 -A -v -PN "
  186. alias nmap-ping="nmap -sP -PE -PA21,23,80,3389 "
  187. alias nmap-quick="nmap -T4 -F "
  188. alias nmap-quick-plus="sudo nmap -sV -T4 -O -F --version-light "
  189. alias nmap-traceroute="sudo nmap -sP -PE -PS22,25,80 -PA21,23,80,3389 -PU -PO --traceroute "
  190. alias nmap-regular="nmap "
  191. 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 "
  192. # Little "safer" scan as connecting to only HTTP and HTTPS ports doesn't look so attacking. Copy-paste to .zsh_custom and remove " -p 80,443" if you want to scan all ports which nmap scans by default.
  193. alias nmap-osscan="sudo nmap -p 80,443 -O -v --osscan-guess --fuzzy "
  194. # Downloads folder over SSH. Usage: rdownload <host>:<remotefolder> <local_destination> | TIP: use ~/ssh/config to configure hosts.
  195. alias rdownload="rsync -h --progress -avz "
  196. alias rscp='rsync -h --progress -avz '
  197. alias rscpr='rsync -h --progress -azvv '
  198. # TMUX specific
  199. alias tmux="tmux -2u"
  200. alias attach="tmux attach-session"
  201. alias detach="tmux detach"
  202. # I am always typoing "aptitude" with my phone...
  203. alias aptitute="aptitude "
  204. # The Battle for Wesnoth specific, http://wesnoth.org/
  205. # It seems to be an good idea to have debug logs on terminal with svn version.
  206. alias wesnoth="wesnoth --debug"
  207. # Auto extension things, ( modified from https://wiki.archlinux.org/index.php/Zsh#Advanced_.zshrc_files )
  208. alias -s html=$BROWSER
  209. alias -s org=$BROWSER
  210. alias -s php=$BROWSER
  211. alias -s com=$BROWSER
  212. alias -s net=$BROWSER
  213. alias -s png="eog"
  214. alias -s jpg="eog"
  215. alias -s gif="eog"
  216. alias -s sxw="libreoffice --writer"
  217. alias -s doc="libreoffice --writer"
  218. alias -s gz='tar -xzvf'
  219. alias -s bz2='tar -xjvf'
  220. #alias -s java=$EDITOR
  221. #alias -s txt=$EDITOR
  222. #alias -s PKGBUILD=$EDITOR
  223. # For copy-pasting directly from somewhere
  224. alias %=" "
  225. alias \#=" "
  226. # Supybot specifig. Why to write long command, if you can write short command?
  227. alias supybot-config-reload="killall -HUP supybot "
  228. alias supybot-owner-quit="killall -INT supybot "
  229. # Translating plugins in Limnoria
  230. alias supybot-generate-messages.pot="pygettext --docstrings config.py plugin.py"
  231. alias supybot-check-plugin-trans="sandbox/check_trans.py plugins/"
  232. alias supybot-check-core-trans="sandbox/check_trans.py --core"
  233. alias supybot-generate-messages.pot-mass="find . -type d -exec sh -c '(cd {} && pygettext --docstrings config.py plugin.py)' ';'"
  234. # ZSH specific.
  235. # I think that "theme" is more describing than "prompt".
  236. alias theme="prompt "
  237. ## -- Start of aliases which are saved from Ubuntu default bashrc. --
  238. # enable color support of ls and also add handy aliases
  239. if [[ $UNAME != Darwin ]]; then
  240. alias ls='ls --color=always'
  241. fi
  242. alias dir='dir --color=always'
  243. alias vdir='vdir --color=always'
  244. alias grep='grep -i --color=always'
  245. alias fgrep='fgrep -i --color=always'
  246. alias egrep='egrep -i --color=always'
  247. # some more ls aliases
  248. if [[ "$UNAME" != "Darwin" ]]; then
  249. alias ll='ls -alFh --color=always' && alias la='ls -A --color=always' && alias l='ls -CF --color=always'
  250. fi
  251. if [[ $UNAME = Darwin ]]; then
  252. alias ls="ls -Gp"
  253. alias ll="ls -alFHGp"
  254. alias l="ls -CFGp"
  255. fi
  256. # Add an "alert" alias for long running commands. Use like so:
  257. 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$//'\'')"'
  258. ## -- End of aliases which are saved from Ubuntu default bashrc. --
  259. # Copying command in Supybot (Internet.DNS)
  260. alias dns="nslookup "
  261. alias dns6="nslookup -type=AAAA "
  262. alias nslookup6="nslookup -type=AAAA "
  263. # If I have nslookup6...
  264. alias dig6="dig AAAA "
  265. # SSHGuard specific
  266. alias sshguard-show-bans="sudo iptables -L sshguard --line-numbers"
  267. # Enter ban number as arguement. You can see ban numbers with previous command.
  268. alias sshguard-unban="sudo iptables -D sshguard "
  269. # This needs something which makes it easy to remember.
  270. alias KILL="killall -KILL "
  271. # For locally rsync copying folder1 to folder2.
  272. alias rsync-folder="rsync -h --progress -azvv "
  273. # SSHGuard seems to prefer users to run this always when connecting with keys in ssh-agent...
  274. if [[ $UNAME != Darwin ]]; then
  275. alias ssh-add="\ssh-add -D && \ssh-add "
  276. fi
  277. # Use GPG2 instead of GPG!
  278. alias gpg=gpg2
  279. compdef gpg2=gpg
  280. export KEYBASE_GPG=gpg2
  281. alias gpg-fix-tty='export GPG_TTY=$(tty)'
  282. # ZSH doesn't currently include automatic completion for GPG2,
  283. # so use the GPG one, which works with GPG2 too. This is in aliases,
  284. # because that above alias needs this and this will disappear when zsh
  285. # gets GPG2 completion. See
  286. # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=666755
  287. #compdef gpg2=gpg # MIKAELA_GREP MIKAELA_GREP_ALIAS
  288. # For locally installed 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 pool.sks-keyservers.net --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. alias unixle="flip -ub "
  318. alias msdosle="flip -mb "
  319. # Making .iso bootable from CD/DVD/USB. Cat it to /dev/<DEVICE>
  320. # MaKe Hybrid ISO
  321. alias mkhiso=isohybrid
  322. # Yum
  323. alias yum-unlock="rm -rf /var/run/yum.pid"
  324. alias yum-rm-timedhosts="rm /var/cache/yum/$CPUARCH/17/timedhost*"
  325. alias yummy="yum -y "
  326. alias yummn="yum -n "
  327. alias yumy=yummy
  328. alias yumn=yummn
  329. # Archiving and extracting with tar
  330. # This is tartar to avoid conflict with tar
  331. alias tartar="tar cfv "
  332. alias targz="tar cfvz "
  333. alias tarbz2="tar cfvj "
  334. # ex-tartar and ex-tar, because there is alias tartar and command tar
  335. alias ex-tar="tar xfv "
  336. alias ex-tartar="tar xfv "
  337. alias ex-targz="tar xfvz "
  338. alias ex-tarbz2="tar xfvj "
  339. # systemd runlevels/targets
  340. alias currenttargets="systemctl list-units --type=target"
  341. alias telsystemd="systemctl isolate "
  342. alias defaulttarget="systemctl enable "
  343. # For getting timestamps in history
  344. alias history="history -i "
  345. # To have less handle ls colours
  346. alias less="less -R "
  347. # "su -" with/without sudo
  348. alias ssu="sudo su -"
  349. alias suu="su -"
  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 Redhad/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 apt-gety="apt-get -y "
  363. alias aptitudey="aptitude -y "
  364. alias apty="apt -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 -s"
  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 *;cd partial;rm *;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 yaourt share the same flags
  454. if hash yaourt 2>/dev/null; then
  455. alias pacman="yaourt --needed"
  456. else
  457. # I don't want to reinstall exact same versions that I have
  458. alias pacman="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. # Allow custom aliases to be put in .aliases or .zsh_aliases .
  467. # .aliases
  468. if [ -f ~/.aliases ]; then
  469. source ~/.aliases
  470. fi
  471. # .zsh_aliases
  472. if [ -f ~/.zsh_aliases ]; then
  473. source ~/.zsh_aliases
  474. fi
  475. ##### Functions ZGC5QQ #####
  476. # GEOIP lookup, improved from the ultimate bashrc http://goo.gl/qGK5j
  477. function geoip() {
  478. geoiplookup $1
  479. geoiplookup6 $1
  480. }
  481. # Checks which package the command comes from. Copied from the ultimate bashrc http://goo.gl/qGK5j
  482. function cmdpkg() { PACKAGE=$(dpkg -S $(which $1) | cut -d':' -f1); echo "[${PACKAGE}]"; dpkg -s "${PACKAGE}" ;}
  483. # Down for everyone or just me? Copied from the ultimate bashrc http://goo.gl/qGK5j
  484. function downforme() {
  485. RED='\e[1;31m'
  486. GREEN='\e[1;32m'
  487. YELLOW='\e[1;33m'
  488. NC='\e[0m'
  489. if [ $# = 0 ]
  490. then
  491. echo -e "${YELLOW}usage:${NC} downforme website_url"
  492. else
  493. JUSTYOUARRAY=($(lynx -dump http://downforeveryoneorjustme.com/$1 | grep -o "It's just you"))
  494. if [ ${#JUSTYOUARRAY} != 0 ]
  495. then
  496. echo -e "${RED}It's just you. \n${NC}$1 is up."
  497. else
  498. echo -e "${GREEN}It's not just you! \n${NC}$1 looks down from here."
  499. fi
  500. fi
  501. }
  502. # Topt10 commands, copied from the ultimate bashrc http://goo.gl/qGK5j
  503. function top10() {
  504. # copyright 2007 - 2010 Christopher Bratusek
  505. \history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head
  506. }
  507. # ex command. Copied from zshrc of bioterror ( http://ricecows.org/configs/zsh/.zshrc ). Original comment below:
  508. ## for unit193 ;)
  509. ## use command "ex" to extract any archive files.
  510. ## "ex package.zip" for example
  511. function ex ()
  512. {
  513. if [ -f "$1" ] ; then
  514. case "$1" in
  515. *.tar) tar xvf $1 ;;
  516. *.tar.bz2 | *.tbz2 ) tar xjvf $1 ;;
  517. *.tar.gz | *.tgz ) tar xzvf $1 ;;
  518. *.bz2) bunzip2 $1 ;;
  519. *.rar) unrar x $1 ;;
  520. *.gz) gunzip $1 ;;
  521. *.zip) unzip $1 ;;
  522. *.Z) uncompress $1 ;;
  523. *.7z) 7z x $1 ;;
  524. *.xz) tar xJvf $1 ;;
  525. *.deb)
  526. DIR=${1%%_*.deb}
  527. ar xv $1
  528. mkdir ${DIR}
  529. tar -C ${DIR} -xzvf data.tar.gz ;;
  530. *.rpm) rpm2cpio $1 | cpio -vid ;;
  531. *) echo ""${1}" cannot be extracted via extract()"
  532. ;;
  533. esac
  534. else
  535. echo ""${1}" is not a valid file"
  536. fi
  537. }
  538. # Given by nyuszika7h. Shortens GitHub URLs with git.io
  539. function gitio() {
  540. curl -s -i http://git.io -F "url=$1" | grep --color=never -P '^Location: ' | awk '{ print $2 }'
  541. }
  542. function mkcd() {
  543. if [[ $# -gt 1 ]]; then
  544. echo 'Warning: All directories will be created, but will change to first specified directory.' 1>&2
  545. fi
  546. mkdir -p "$*" && cd "$1"
  547. }
  548. function gribble-gpg-everify() {
  549. # Set which command to use for gpg. You
  550. # probably want to use gpg2 here.
  551. local gpg=gpg2
  552. echo -n 'Enter Bitcoin OTC URL: '
  553. read REPLY
  554. lynx -hiddenlinks=ignore -dump $REPLY > bitcoin_otc.txt.asc
  555. $gpg --decrypt-file bitcoin_otc.txt.asc
  556. echo -en '\e[1;32m;;everify '
  557. cat bitcoin_otc.txt
  558. echo -e '\e[0m'
  559. rm -rf bitcoin_otc.txt bitcoin_otc.txt.asc
  560. }
  561. # This function will install/upgrade shell-things.
  562. function shell-things {
  563. export SHELL_THINGS_REPO=$HOME/.shell-things
  564. # Check if ~/.shell-things exists and cd and pull.
  565. if [ -d $SHELL_THINGS_REPO ]; then
  566. echo "shell-things: $SHELL_THINGS_REPO exists, git pulling..."
  567. echo ""
  568. cd $SHELL_THINGS_REPO
  569. git remote set-url origin https://github.com/Mikaela/shell-things.git
  570. git pull
  571. echo ""
  572. echo "shell-things: Installing/Upgrading..."
  573. echo ""
  574. # If it doesn't exist...
  575. else
  576. echo ""
  577. echo "shell-things: $SHELL_THINGS_REPO doesn't exist, cloning..."
  578. echo ""
  579. git clone https://github.com/Mikaela/shell-things.git $SHELL_THINGS_REPO
  580. cd $SHELL_THINGS_REPO
  581. echo ""
  582. echo "shell-things: Installing/Upgrading..."
  583. echo ""
  584. fi
  585. # Installing...
  586. bash -x ./install
  587. echo ""
  588. echo "shell-things: Installing finished."
  589. echo ""
  590. echo ""
  591. echo "shell-things: Everthing is now done :)"
  592. echo ""
  593. cd
  594. }
  595. # This function will download and install sources.list.
  596. function sources-list-install {
  597. export RELEASE=$(lsb_release -sr)
  598. a[1]="https://raw.githubusercontent.com/Mikaela/shell-things/master/etc/apt/sources.list/$RELEASE"
  599. echo "I am now changing directory to /etc/apt/."
  600. echo ""
  601. cd /etc/apt/
  602. echo "I will now backup sources.list to sources.list.bak ."
  603. echo ""
  604. cp /etc/apt/sources.list /etc/apt/sources.list.bak
  605. 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 ."
  606. echo ""
  607. echo "" > /etc/apt/sources.list
  608. \wget ${a[1]} -O /etc/apt/sources.list
  609. #\curl -L ${a[1]} >> /etc/apt/sources.list
  610. echo ""
  611. echo "The new sources.list file should now be installed."
  612. echo ""
  613. echo "Finally, I will now run 'apt-get -y update' so the new sources.list is used."
  614. echo ""
  615. apt-get update
  616. echo "I have now finished everything that I was supposed to do."
  617. }
  618. # Same for Debian (codename instead of release)
  619. function sources-list-install-debian {
  620. export RELEASE=$(lsb_release -sc)
  621. a[1]="https://raw.githubusercontent.com/Mikaela/shell-things/master/etc/apt/sources.list/$RELEASE"
  622. echo "I am now changing directory to /etc/apt/."
  623. echo ""
  624. cd /etc/apt/
  625. echo "I will now backup sources.list to sources.list.bak ."
  626. echo ""
  627. cp /etc/apt/sources.list /etc/apt/sources.list.bak
  628. 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 ."
  629. echo ""
  630. echo "" > /etc/apt/sources.list
  631. \wget ${a[1]} -O /etc/apt/sources.list
  632. #\curl -L ${a[1]} >> /etc/apt/sources.list
  633. echo ""
  634. echo "The new sources.list file should now be installed."
  635. echo ""
  636. echo "Finally, I will now run 'apt-get -y update' so the new sources.list is used."
  637. echo ""
  638. apt-get update
  639. echo "I have now finished everything that I was supposed to do."
  640. }
  641. # This function fixes nodejs on Debian based systems.
  642. # (Everything expects nodejs to be called as node, but it's not with Debian.)
  643. function fix-node {
  644. if [[ $USER = "root" && -f /usr/bin/nodejs && ! -f /usr/bin/node && ! -f /usr/local/bin/node ]] then;
  645. ln -s /usr/bin/nodejs /usr/local/bin/node
  646. fi
  647. mkdir -p $HOME/.local/bin
  648. if [[ -f /usr/bin/nodejs && ! -f /usr/bin/node && ! -f /usr/local/bin/node && ! -f $HOME/.local/bin/node ]] then;
  649. ln -s /usr/bin/nodejs $HOME/.local/bin/node
  650. fi
  651. }
  652. # This function fixes automatic startup in graphical sessions.
  653. # I have had issues with auto start not doing anything and this seems to
  654. # fix it.
  655. fix-autostart() {
  656. if [[ $USER = "root" ]]
  657. then
  658. mkdir -p /etc/xdg/autostart
  659. chmod -R 755 /etc/xdg/autostart
  660. fi
  661. mkdir -p ~/.config/autostart
  662. chmod -R 755 ~/.config/autostart
  663. }
  664. # This function removes and regenerates ssh host keys.
  665. ssh-regen-host-keys () {
  666. rm /etc/ssh/ssh_host_*
  667. ssh-keygen -t dsa -N "" -f /etc/ssh/ssh_host_dsa_key
  668. ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key
  669. ssh-keygen -t ecdsa -N "" -f /etc/ssh/ssh_host_ecdsa_key
  670. ssh-keygen -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key
  671. }
  672. # This function erases Master Boot Record from device
  673. # Note: this is dangerous so this function will echo the command
  674. # instad of running it!
  675. erase-mbr() {
  676. echo dd if=/dev/zero of=$1 bs=512 count=2
  677. }
  678. # Use clang if installed. It seems interesting and this is probably good
  679. # way to test it. This might not be a function, but I don't have any better
  680. # place for this.
  681. if hash clang 2>/dev/null; then
  682. export CC=clang
  683. export HOMEBREW_CC=clang
  684. fi
  685. if hash clang++ 2>/dev/null; then
  686. export CXX=clang++
  687. fi
  688. # Add GitHub pull requests to fetched things via http://git.io/-C-0oQ
  689. github-add-pulls() {
  690. git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
  691. git config --add remote.upstream.fetch '+refs/pull/*/head:refs/remotes/upstream/-pr/*'
  692. }
  693. # Get server SSL certificate fingerprint in MD5, SHA1 and SHA256.
  694. # Note that OpenSSL doesn't support IPv6 at time of writing (2015-01-13).
  695. serversslcertfp () {
  696. SSSLCFFN=$(openssl s_client -showcerts -connect $1 < /dev/null)
  697. # To see all validity information
  698. echo "$SSSLCFFN"
  699. # For getting the fingerprints
  700. echo "$SSSLCFFN" | openssl x509 -md5 -fingerprint -noout
  701. echo "$SSSLCFFN" | openssl x509 -sha1 -fingerprint -noout
  702. echo "$SSSLCFFN" | openssl x509 -sha256 -fingerprint -noout
  703. unset SSSLCFFN
  704. }
  705. # The same for local certificate file
  706. sslcertfp () {
  707. cat $1 | openssl x509 -md5 -fingerprint -noout
  708. cat $1 | openssl x509 -sha1 -fingerprint -noout
  709. cat $1 | openssl x509 -sha256 -fingerprint -noout
  710. }
  711. # Usage: serversslciphers hostname port
  712. serversslciphers() {
  713. nmap -Pn $1 -p $2 --script +ssl-enum-ciphers
  714. }
  715. # Generate SSL certificate
  716. sslgenpem () {
  717. openssl req -nodes -newkey rsa:4096 -keyout $1.pem -x509 -days 3650 -out $1.pem -subj "/CN=$2"
  718. }
  719. # Managing SSL certificates of Google Chrome
  720. chrome-add-cert () {
  721. echo "Please ensure that either libnss3-tools or nss-tools is installed."
  722. certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n $1 -i $1
  723. }
  724. chrome-list-certs () {
  725. echo "Please ensure that either libnss3-tools or nss-tools is installed."
  726. certutil -d sql:$HOME/.pki/nssdb -L # add '-h all' to see all built-in certs
  727. }
  728. ssldownloadcert () {
  729. echo "Please ensure that either libnss3-tools or nss-tools is installed."
  730. echo QUIT | openssl s_client -connect $1:443 | sed -ne '/BEGIN CERT/,/END CERT/p' | tee $1.pem
  731. }
  732. # Getting magnet from transmission-daemon
  733. transmission-torrents () {
  734. transmission-remote -l
  735. }
  736. transmission-magnet () {
  737. transmission-remote -l -t $1 -i | grep magnet
  738. }
  739. git-squash () {
  740. git reset --soft HEAD~$1
  741. git commit
  742. }
  743. # Combining mtrp4 & mtrp6
  744. mtrp() {
  745. mtrp4 $@
  746. mtrp6 $@
  747. }
  748. # My IPv4 address
  749. myip4 () {
  750. if hash dig 2>/dev/null; then
  751. dig +short myip.opendns.com. A @208.67.222.222
  752. else
  753. curl -L4s http://icanhazip.com/
  754. fi
  755. }
  756. # My IPv6 address
  757. myip6 () {
  758. if hash dig 2>/dev/null; then
  759. dig +short myip.opendns.com. AAAA @2620:0:ccc::2
  760. else
  761. curl -L6s http://icanhazip.com/
  762. fi
  763. }
  764. # Source files for miscannellious modifications.
  765. # .custom
  766. if [ -f ~/.custom ]; then
  767. source ~/.custom
  768. fi
  769. # .zsh_custom
  770. if [ -f ~/.zsh_custom ]; then
  771. source ~/.zsh_custom
  772. fi
  773. # Warnings
  774. if [ -f ~/.warnings ]; then
  775. source ~/.warnings
  776. fi