From 993f162a2f9841b3bd876776b92855efff2c618f Mon Sep 17 00:00:00 2001 From: Mika Suomalainen Date: Thu, 29 Sep 2011 15:25:05 +0300 Subject: [PATCH] Forked bash-things to zsh-things. Converted everything to work with zsh. Some things can be little weird because moving is still going on. --- .gitignore | 1 - README | 27 ++++++---------- install.sh | 49 +++++++++++++---------------- uninstall.sh | 13 ++++---- upgrade.sh | 40 +++++++++++------------- zsh_aliases | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ zsh_exports | 19 ++++++++++++ zsh_functions | 55 ++++++++++++++++++++++++++++++++ zshrc | 57 ++++++++++++++++++++++++++++++++++ 9 files changed, 272 insertions(+), 75 deletions(-) create mode 100755 zsh_aliases create mode 100644 zsh_exports create mode 100644 zsh_functions create mode 100644 zshrc diff --git a/.gitignore b/.gitignore index 556d3f29..d3ee8da4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ # It seems that running install.sh causes ~ files in this git repo. They are lockfiles. *~ -# I am too lazy to push this to three places. push.sh diff --git a/README b/README index ce40f083..05db5ec7 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Bashrc file and other files which it depends on by Mika Suomalainen (Mkaysi). +zshrc file and other files which it depends on by Mika Suomalainen (Mkaysi). INSTALLATION: Move to folder of this git repo. @@ -13,20 +13,14 @@ chmod +x ./uninstall.sh WARNING! DO NOT USE INSTALL.SH TO UPDATE OR YOU WILL LOSE AUTOMATIC BACKUP, WHICH WAS TAKEN WHEN YOU RAN INSTALLATION SCRIPT. -TESTED OPERATING SYSTEMS: -Ubuntu 11.04 # Everything works -Debian (Sid) # Everything seems to work. -Mac OS X (Snow Leopard) # Everything seems to work after disabling autocd (disabled by default because of this.) Bash in Mac seems to have weird settings, because it looks so different when compared to Ubuntu or Debian. -Arch Linux # Everything seems to work. Bash in Arch Linux seems to have weird default settings, because it looks so weird when compared to Ubuntu or Debian. - Notices: -bashrc: I have uncommented line 42. -bash_exports: The default editor is nano (line 4). -bash_exports: The default timezone is Europe/Helsinki, line 15. You probably want to change it. -bashrc: autocd is disabled (commented in near end of bashrc REASON: It doesn't seem to work with Mac OS X, and I have one MacBook running it here.. -bashrc: Lines 123-125 expect you to have tmux installed. -bash_exports: Line 11 makes C as locale. You MUST change this. See line 10 for information about how. -bashrc: if you have read every notice, comment line 1 in your ~/.bashrc . +zshrc: I have uncommented line 42. +zsh_exports: The default editor is nano (line 4). +zsh_exports: The default timezone is Europe/Helsinki, line 15. You probably want to change it. +zshrc: autocd is disabled (commented in near end of zshrc REASON: It doesn't seem to work with Mac OS X, and I have one MacBook running it here.. +zshrc: Lines 123-125 expect you to have tmux installed. +zsh_exports: Line 11 makes C as locale. You MUST change this. See line 10 for information about how. +zshrc: if you have read every notice, comment line 1 in your ~/.zshrc . DISCLAIMER: Author of this git repository is not responsible for any data loss or any other harms, which might be @@ -39,7 +33,4 @@ There aren't any license, but please mention that I created this and where did y If something is copy-pasted here from somewhere, it reads in that file. Original sources: -GitHub gist: (This first appeared here) https://gist.github.com/1142884 -GitHub: Because this has 9 files, I created repo for this: https://github.com/Mkaysi/bash-things -Mirror: (This is mirror where I am mirrorring all of my git repositories / forks, please note that it's usually down) http://mkaysi.dyndns.org/git/?p=Mkaysi/bash-things.git;a=summary -(Please note that I am pushing to all of them.) +GitHub gist: (This first appeared here) https://gist.github.com/1248723 diff --git a/install.sh b/install.sh index f33dbef5..d5a2de88 100755 --- a/install.sh +++ b/install.sh @@ -1,31 +1,26 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh echo "If you are upgrading, press ctrl + c NOW! You have 15 seconds time to cancel this. rerunning this script will overwrite your backups and it makes uninstall.sh useless." sleep 15; echo "Taking backups..." -touch ~/.bashrc # Creates .bashrc if you don't have one. -cat ~/.bashrc > ~/.bashrc.default.backup # Backups your current .bashrc -touch ~/.bash_aliases # Creates .bash_aliases if you don't have one. -cat ~/.bash_aliases > ~/.bash_aliases.default.backup # Backups your current .bash_aliases -touch ~/.bash_profile # Creates .bash_profile if you don't have it already. -cat ~/.bash_profile > ~/.bash_profile.default.backup # Back ups your current bash_profile. -touch ~/.bash_exports # Creates .bash_exports (this is my idea, I am surprised if you have it.) -cat ~/.bash_exports > ~/.bash_exports.default.backup # Backs up .bash_exports. -touch ~/.bash_functions # I am surprised if you have this, see above. -cat ~/.bash_functions > ~/.bash_functions.default.backup # Backs up .bash_functions . +touch ~/.zshrc # Creates .zshrc if you don't have one. +cat ~/.zshrc > ~/.zshrc.default.backup # Backups your current .zshrc +touch ~/.zsh_aliases # Creates .zsh_aliases if you don't have one. +cat ~/.zsh_aliases > ~/.zsh_aliases.default.backup # Backups your current .zsh_aliases +touch ~/.zsh_exports # Creates .zsh_exports (this is my idea, I am surprised if you have it.) +cat ~/.zsh_exports > ~/.zsh_exports.default.backup # Backs up .zsh_exports. +touch ~/.zsh_functions # I am surprised if you have this, see above. +cat ~/.zsh_functions > ~/.zsh_functions.default.backup # Backs up .zsh_functions . echo "Done!" -echo "Installing bash_aliases." -cat bash_aliases > ~/.bash_aliases -echo "bash_aliases installed." -echo "Installing bash_profile" -cat bash_profile > ~/.bash_profile -echo "bash_profile installed." -echo "Installing bashrc." -cat bashrc > ~/.bashrc -echo "bashrc installed." -echo "Installing bash_exports" -cat bash_exports > ~/.bash_exports -echo "bash_exports installed." -echo "Installing bash_functions" -cat bash_functions > ~/.bash_functions -echo "bash_functions installed." -echo "Installation has completed. Now run 'source ~/.bashrc' to enable the new things." +echo "Installing zsh_aliases." +cat zsh_aliases > ~/.zsh_aliases +echo "zsh_aliases installed." +echo "Installing zshrc." +cat zshrc > ~/.zshrc +echo "zshrc installed." +echo "Installing zsh_exports" +cat zsh_exports > ~/.zsh_exports +echo "zsh_exports installed." +echo "Installing zsh_functions" +cat zsh_functions > ~/.zsh_functions +echo "zsh_functions installed." +echo "Installation has completed. Now run 'source ~/.zshrc' to enable the new things." diff --git a/uninstall.sh b/uninstall.sh index 8fa630e1..481b6111 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,8 +1,7 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh echo "Restoring default files..." -cat ~/.bashrc.default.backup > ~/.bashrc -cat ~/.bash_aliases.default.backup > ~/.bash_aliases -cat ~/.bash_profile.default.backup > ~/.bash_profile -cat ~/.bash_exports.default.backup > ~/.bash_exports -cat ~/.bash_functions.default.backup > ~/.bash_functions -echo "Done! Now you should restart bash or source files again for default files to affect." +cat ~/.zshrc.default.backup > ~/.zshrc +cat ~/.zsh_aliases.default.backup > ~/.zsh_aliases +cat ~/.zsh_exports.default.backup > ~/.zsh_exports +cat ~/.zsh_functions.default.backup > ~/.zsh_functions +echo "Done! Now you should restart zsh or source files again for default files to affect." diff --git a/upgrade.sh b/upgrade.sh index 46d9e890..e179bed0 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -1,24 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh echo "Backing up files..." -touch ~/.bash_exports -cat ~/.bash_exports > ~/.bash_exports.old.backup -touch ~/.bash_profile -cat ~/.bash_profile > ~/.bash_profile.old.backup -touch ~/.bash_aliases -cat ~/.bash_aliases > ~/.bash_aliases.old.backup -touch ~/.bash_functions -cat ~/.bash_functions > ~/.bash_functions.old.backup -touch ~/.bashrc -cat ~/.bashrc > ~/.bashrc.old.backup +touch ~/.zsh_exports +cat ~/.zsh_exports > ~/.zsh_exports.old.backup +touch ~/.zsh_aliases +cat ~/.zsh_aliases > ~/.zsh_aliases.old.backup +touch ~/.zsh_functions +cat ~/.zsh_functions > ~/.zsh_functions.old.backup +touch ~/.zshrc +cat ~/.zshrc > ~/.zshrc.old.backup echo "Installing new files..." -cat bash_profile > ~/.bash_profile -cat bash_aliases > ~/.bash_aliases -cat bash_functions > ~/.bash_functions -cat bashrc > ~/.bashrc -echo "Not installing bash_exports, See content of that file:" -touch ~/.bash_exports -echo "-- Start of content of bash_exports --" -cat bash_exports -echo "-- End of content of bash_exports --" -echo "-- end of content of bash_private_aliases --" -echo "Installation has been completed. You might now need to source your ~/.bashrc for changes to happen." +cat zsh_aliases > ~/.zsh_aliases +cat zsh_functions > ~/.zsh_functions +cat zshrc > ~/.zshrc +echo "Not installing zsh_exports, See content of that file:" +touch ~/.zsh_exports +echo "-- Start of content of zsh_exports --" +cat zsh_exports +echo "-- End of content of zsh_exports --" +echo "Installation has been completed. You might now need to source your ~/.zshrc for changes to happen." diff --git a/zsh_aliases b/zsh_aliases new file mode 100755 index 00000000..728ebcaf --- /dev/null +++ b/zsh_aliases @@ -0,0 +1,86 @@ +# This file contains aliases which my bashrc uses. You might need to edit something (for example: if you use vi or don't have nmap). + +# To get sudo work with aliases. +alias sudo="sudo " + +# Moving between directories: +alias ..="cd .." +alias .="cd ." + +# As you can see, I don't use/like Vi(m) :) +alias editor="nano" +alias vi="nano" +alias vim="nano" + +# Use htop instead of top, it's better. Requires htop. +alias top="htop" + +# Automaticly adds title to Youtube-dl when downloading videos with it. Requires youtube-dl. +alias youtube-dl="youtube-dl -t" + +# 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. +alias gdrop="git stash && git stash drop" +alias gitk="gitg" # Requires gitg . I just think that it looks nicer than gitk. + +# Usually when I run "time", I want to know the current time. +alias time="date" + +# If I run nautilus, I want it to open in folder where I am. +alias nautilus="nautilus ./" + +# Why I must write "weechat-curses" to start it? +alias weechat="weechat-curses" + +#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. +alias nmap-intense="nmap -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 " +alias nmap-intense-udp="sudo nmap -sS -sU -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 " +alias nmap-intense-all-tcp="nmap -p 1-65535 -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 " +alias nmap-intense-no-ping="nmap -T4 -A -v -PN " +alias nmap-ping="nmap -sP -PE -PA21,23,80,3389 " +alias nmap-quick="nmap -T4 -F " +alias nmap-quick-plus="sudo nmap -sV -T4 -O -F --version-light " +alias nmap-traceroute="sudo nmap -sP -PE -PS22,25,80 -PA21,23,80,3389 -PU -PO --traceroute " +alias nmap-regular="nmap " +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 " +alias ping="nping " +alias netcat="ncat " +# More nmap specific things, but these also require proxychains. WANTED: better abreviation (than pc) for proxyc. +alias proxyc-nmap-intense="proxychains nmap -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 " +alias proxyc-nmap-intense-udp="sudo proxychains nmap -sS -sU -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 " +alias proxyc-nmap-intense-all-tcp="proxychains nmap -p 1-65535 -T4 -A -v -PE -PS22,25,80 -PA21,23,80,3389 " +alias proxyc-nmap-intense-no-ping="proxychains nmap -T4 -A -v -PN " +alias proxyc-nmap-ping="proxychains nmap -sP -PE -PA21,23,80,3389 " +alias proxyc-nmap-quick="proxychains nmap -T4 -F " +alias proxyc-nmap-quick-plus="sudo proxychains nmap -sV -T4 -O -F --version-light " +alias proxyc-nmap-traceroute="sudo proxychains nmap -sP -PE -PS22,25,80 -PA21,23,80,3389 -PU -PO --traceroute " +alias proxyc-nmap-regular="proxychains nmap " +alias proxyc-nmap-comprehensive="sudo proxychains nmap -sS -sU -T4 -A -v -PE -PP -PS21,22,23,25,80,113,31339 -PA80,113,443,10042 -PO --script all " +alias proxyc-nmap="proxychains nmap" +alias proxyc-nmapfe="proxychains nmapfe" +alias proxyc-ping="proxychains nmap nping " +alias proxyc-netcat="proxychains nmap ncat " + +# TOR (The Onion Router) specific. +alias usewithtor="proxychains " +alias torsocks="proxychains " + +# Because I have so many proxyc aliasses and some people want to access proxychains quickly. +alias proxyc="proxychains " + +# Downloads folder over SSH. Usage: rdownload : | TIP: use ~/ssh/config to configure hosts. +alias rdownload="rsync -avz " + +# TMUX specific +alias attach="tmux -u attach-session" +alias detach="tmux -u detach" +alias tmux="tmux -u" + +# I am always typoing "aptitude" with my phone... +alias aptitute="aptitude " + +# This is the checkinstall rule which I like to use. +alias checkinstall="make install " + +# The Battle for Wesnoth specific, http://wesnoth.org/ +# It seems to be an good idea to have debug logs on terminal with svn version. +alias wesnoth="wesnoth --debug" diff --git a/zsh_exports b/zsh_exports new file mode 100644 index 00000000..cced5f73 --- /dev/null +++ b/zsh_exports @@ -0,0 +1,19 @@ +# This file exports everything in my zshrc. Note: This file is not overwritten by scripts. + +# Sets the default editor. I prefer nano to vim and so on, so I want it to be nano. If you don't like terminal based text editors, change "nano" to gedit (Gnome) or Kate (KDE). +export EDITOR=nano + +# Sets user specifig PYTHONPATH. Replace 2.X with your Python version. For example with Python 2.7 you replace X with 7. +#export PYTHONPATH=$HOME/.packages/lib/python2.X/site-packages + +# Fixes locale problems (for example) when SSHing in with different locale. (Another example: Hailo plugin for supybot gives locale errors, this fixes it.) +# Replace "C" with your locale. You can get list of locales by running "locale -a". Replace "C" with your language. For example: fi_FI.utf8 ) +LC_ALL=C +export LC_ALL + +# Sets your timezone. Set in format , or just timezone like UTC. +#export TZ="/usr/share/zoneinfo/Europe/Helsinki" + +# Sets PATH. To add another path, add : to string below. +# Yes, I know that this isn't exporting, but I don't want PYTHONPATH to be alone here and PATH matches with nature of this file. +PATH=$PATH diff --git a/zsh_functions b/zsh_functions new file mode 100644 index 00000000..4713fc5a --- /dev/null +++ b/zsh_functions @@ -0,0 +1,55 @@ +# This file contains functions of my zshrc. You probably don't need to edit anything here. +# +# Most of things here are originally from bash. +# +# To disable function, just comment everything after description. + +# GEOIP lookup, copied from the ultimate bashrc http://goo.gl/qGK5j +function geoip() { +geoiplookup $1 +} + +# MYIP, copied from the ultimate bashrc http://goo.gl/qGK5j . I think that it requires lynx. +function myip() +{ +lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ print $4 }' | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' +} + +# Checks which package the command comes from. Copied from the ultimate bashrc http://goo.gl/qGK5j +function cmdpkg() { PACKAGE=$(dpkg -S $(which $1) | cut -d':' -f1); echo "[${PACKAGE}]"; dpkg -s "${PACKAGE}" ;} + +# ROT13, copied from the ultimate bashrc http://goo.gl/qGK5j +function rot13() +{ + if [ $# -lt 1 ] || [ $# -gt 1 ]; then + echo "Seriously? You don't know what rot13 does?" + else + echo $@ | tr A-Za-z N-ZA-Mn-za-m + fi +} + +# Down for everyone or just me? Copied from the ultimate bashrc http://goo.gl/qGK5j +function downforme() { + RED='\e[1;31m' + GREEN='\e[1;32m' + YELLOW='\e[1;33m' + NC='\e[0m' + if [ $# = 0 ] + then + echo -e "${YELLOW}usage:${NC} downforme website_url" + else + JUSTYOUARRAY=(`lynx -dump http://downforeveryoneorjustme.com/$1 | grep -o "It's just you"`) + if [ ${#JUSTYOUARRAY} != 0 ] + then + echo -e "${RED}It's just you. \n${NC}$1 is up." + else + echo -e "${GREEN}It's not just you! \n${NC}$1 looks down from here." + fi + fi +} + +# Topt10 commands, copied from the ultimate bashrc http://goo.gl/qGK5j +function top10() { + # copyright 2007 - 2010 Christopher Bratusek + history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head +} diff --git a/zshrc b/zshrc new file mode 100644 index 00000000..e438c985 --- /dev/null +++ b/zshrc @@ -0,0 +1,57 @@ +echo "Please see the README file." + +# This is based on zshrc which came with Debian (Third option in wizard for new users.) + +# Set up the prompt + +autoload -Uz promptinit +promptinit +prompt adam1 + +setopt histignorealldups sharehistory + +# Use emacs keybindings even if our EDITOR is set to vi +bindkey -e + +# Keep 1000 lines of history within the shell and save it to ~/.zsh_history: +HISTSIZE=1000 +SAVEHIST=1000 +HISTFILE=~/.zsh_history + +# Use modern completion system +autoload -Uz compinit +compinit + +zstyle ':completion:*' auto-description 'specify: %d' +zstyle ':completion:*' completer _expand _complete _correct _approximate +zstyle ':completion:*' format 'Completing %d' +zstyle ':completion:*' group-name '' +zstyle ':completion:*' menu select=2 +eval "$(dircolors -b)" +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' list-colors '' +zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s +zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*' +zstyle ':completion:*' menu select=long +zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s +zstyle ':completion:*' use-compctl false +zstyle ':completion:*' verbose true + +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' +zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' + +# Sources everything. +source ~/.zsh_aliases +source ~/.zsh_exports +source ~/.zsh_functions + +## DO NOT PUT ANYTHING BELOW THIS LINE OR YOUR CHANGES MAY GET IGNORED BY BASH! +sleep 1; + +# Gives three seconds time to press CTRL + C in case you want to prevent action by tmux. + +# Starts tmux always on start of bash, not only on SSH login, and quits from bash when tmux quits. WARNING: I DON'T KNOW WHAT HAPPENS IF YOU DON'T HAVE TMUX INSTALLED! (Modified from Cubox's script and William Shallum's tmux on SSH login http://william.shallum.net/random-notes/automatically-start-tmux-on-ssh-login ) +if [[ $TERM != "screen" ]] +then + tmux has-session -t 0 && tmux attach-session -t 0 || tmux new-session -s 0 && exit +fi