dotfiles/zsh/functions.zsh

129 lines
2.8 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"
}
vs() {
v $1 -c ":vs $2"
}
sp() {
v $1 -c ":sp $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
}
### 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
}
# cdg : cd to a git repo
if [ -d "$GCLONE_PATH" ]; then
cdg() {
if [ $# -ne 1 ]; then
echo "This function expects a single parameter"
return 1
else
dir=`find $GCLONE_PATH -maxdepth 3 -name $1`
if [[ "" == "$dir" ]]; then
echo "$1 not found"
return 2
elif [ `echo $dir | wc -l` -gt 1 ]; then
echo "Multiple entries for $1 found"
return 3
else
cd $dir
fi
fi
}
_cdg() {
_arguments "1: :($(find $GCLONE_PATH -maxdepth 3 -exec basename {} \;))"
}
compdef _cdg cdg
fi
# Music things
# command -v music-server > /dev/null 2>&1
# if [ $? -eq 0 ]; then
# mplayer() {
# ps -e | grep music-server > /dev/null 2>&1
# if [ $? -ne 0 ]; then
# nohup music-server > /dev/null 2>&1 &
# disown
# sleep 0.2s
# fi
# filename=$(echo `realpath $1` | sed 's/ /\\\\ /g' | sed "s/'/\\\\\\\\'/g")
# awesome-client "require('music').execute_command('file ' .. \"$filename\")"
# }
# fi