dotfiles/zsh/functions.zsh

91 lines
1.9 KiB
Bash

# Some helping functions
### File manipulation ###
# Copy to clipboard
copy() {
if [ $# -eq 0 ]; then
xclip -selection c
else
cat $1 | xclip -selection c
fi
}
# Swap files
swap() {
local tmp=`mktemp`
mv "$1" "$tmp"
mv "$2" "$1"
mv "$tmp" "$2"
}
# mkdir && cd
mkcd() {
mkdir $1 && cd $1
}
### Vim helpers ###
vclass() {
v src/"$1".cpp -c ":vs include/$1.hpp"
}
vide() {
v $1 -c ":NERDTree"
}
v2() {
v $1 -c ":vs $2"
}
vfind() {
v `find . -name "$1"`
}
### Awesome functions ###
# Wallpaper change
wallpaper() {
case $1 in
'vixen' ) echo "change_wallpaper('vixen.jpg');" | awesome-client;;
'vixen2' ) echo "change_wallpaper('vixen2.jpg');" | awesome-client;;
'arch' ) echo "change_wallpaper('arch4.png');" | awesome-client;;
'harley' ) echo "change_wallpaper('1200custom.png');" | awesome-client;;
*) return -1
esac
}
# Notify to awesome
notify() {
if [ $# -lt 2 ]; then
echo "naughty.notify({text = \"$1\", timeout = 10})" | awesome-client
elif [ $# -lt 3 ]; then
echo "naughty.notify({title=\"$1\", text = \"$2\", timeout = 10})" | awesome-client
fi
}
### Others ###
# colors for the man pages
man() {
env LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# Better svn log
svn() {
case $* in
log ) shift 1; command svn log "$@" | less ;;
* ) command svn "$@" ;;
esac
}
# Clears resolv.conf with google's dns
resolv() {
echo 'nameserver 8.8.8.8' | sudo tee /etc/resolv.conf > /dev/null
}
# Generate a standard LaTeX maefile
makelatex() {
cp /home/thomas/.script/classgen/Makefile.latex ./Makefile
}