Skip to content

Instantly share code, notes, and snippets.

@janoka
Last active February 19, 2017 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janoka/6fdecdd4c61bbf06256466629f41210d to your computer and use it in GitHub Desktop.
Save janoka/6fdecdd4c61bbf06256466629f41210d to your computer and use it in GitHub Desktop.
Zsh resources
#!/bin/zsh
# Development
# SSH agent load
{ eval `ssh-agent`; ssh-add -K ~/.ssh/id_rsa} &>/dev/null
# Drush
alias d='drush'
alias dy='drush -y'
alias ddl='drush dl'
alias dcc='drush -y cc all'
# Checking composer.
if [ -d ~/.composer ] ; then
export COMPOSER_HOME=~/.composer
export PATH=~/.composer/vendor/bin:"${PATH}"
fi
# Database function.
db() {
# Display the help text.
HELP=$(echo -e "Usage:\n db <parameters>\n \nParameters:\n list|l [<filter for databases>] - listing databases.\n table|t <database> [<table filter>] - tables of database.\n create|c <database> [<user> [<password>]] - create a database, with full grants for user@localhost.\n drupal|d <database> - create a database, drupal@localhost user has a full rights.\n drop <database> - drop the database.\n drop-tables|dt <database> - drop tables in database.\n dump|du <database> [<gzip file path>] - database dump creating.\n restore|re <database> <gzip dump file path> - restore from database dump.\n copy|co <source database> <destination database> - copy from source to destination (table of destination will be dropped before).\n grant|g <database> <user> [<password>] - for user@localhost gives rights.\n revoke|rv <database> <user> - revoke rights of a user@localhost.\n rights|ri <user> - user@localhost rights.\n \n")
if [ -z "${1}" ]; then echo -e "Nincs paraméter megadva.\n\n$HELP"
else
case $1 in
list | l)
# List the databases.
# If you give a parameter, than it fiter the databases names.
if [ ! -z "${2}" ]; then
mysql -e "show databases like '%${2}%'"
else
mysql -e "show databases"
fi;;
create | c)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
else
# Adatbázis létrehozása
mysql -e "create database ${2} default character set utf8 default collate utf8_hungarian_ci";
if [ ! -z "${4}" ]; then
# Jelszó megadása is
mysql -e "grant all on ${2}.* to ${3}@localhost identified by '${4}'; show grants for ${3}@localhost"
elif [ ! -z "${3}" ]; then
# Nincs jelszó megadva, csak a jogok beállítva
mysql -e "grant all on ${2}.* to ${3}@localhost; show grants for ${3}@localhost"
fi
fi ;;
drupal | d)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
else
# Creating database.
mysql -e "create database ${2} default character set utf8 default collate utf8_hungarian_ci; grant all on ${2}.* to drupal@localhost; show grants for drupal@localhost"
fi ;;
drop)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
else
mysql -e "drop database if exists ${2};"
fi ;;
drop-tables | dt)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
else
mysql -e "drop database if exists ${2}; create database ${2}"
fi ;;
grant | g)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
else
if [ ! -z "${4}" ]; then
# Jelszó megadása is
mysql -e "grant all on ${2}.* to ${3}@localhost identified by '${4}'; show grants for ${3}@localhost"
elif [ ! -z "${3}" ]; then
# Nincs jelszó megadva, csak a jogok beállítva
mysql -e "grant all on ${2}.* to ${3}@localhost; show grants for ${3}@localhost"
fi
fi ;;
revoke | rv)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
elif [ -z "${3}" ]; then echo -e "Nincs user megadva.\n\n$HELP"
else
mysql -e "revoke all on ${2}.* from ${3}@localhost; show grants for ${3}@localhost"
fi ;;
rights | ri)
if [ -z "${2}" ]; then echo -e "Username is missing.\n\n$HELP"
else
mysql -e "show grants for ${2}@localhost"
fi ;;
tables | t)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
else
# Ha megadott a tábla szűkítése is.
if [ ! -z "${3}" ]; then
mysql -e "show tables like '%${3}%'" ${2}
else
mysql -e "show tables" ${2}
fi
fi ;;
dump | du)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
else
DATE=$(date +%Y%m%d-%H%M)
# Ha megadott fájlnév is.
if [ ! -z "${3}" ]; then
mysqldump ${2} | gzip > ${3}-$DATE.mysql.gz
else
mysqldump ${2} | gzip > ${2}-$DATE.mysql.gz
fi
fi ;;
restore | re)
if [ -z "${2}" ]; then echo -e "Database name is missing.\n\n$HELP"
elif [ -z "${3}" ]; then echo -e "Dump filename is missing.\n\n$HELP"
elif [ ! -f "${3}" ]; then echo -e "Not existing ${3} dump file.\n\n$HELP"
else
zcat ${3} | mysql ${2}
fi ;;
copy | co)
if [ -z "${2}" ]; then echo -e "Undefined source database.\n\n$HELP"
elif [ -z "${3}" ]; then echo -e "Undefined destination database.\n\n$HELP"
else
mysql -e "drop database if exists ${3}; create database ${3} default character set utf8;"
# mysqladmin create ${3}
mysqldump ${2} | mysql ${3}
fi ;;
esac
fi
}
runtime() {
START=$(date +%s)
$($@)
END=$(date +%s)
echo $(($END-$START)) | awk '{print "Duration: "int($1/60)":"int($1%60)" (sec: "$1")"}'
}
#!/bin/zsh
if [[ "$OSTYPE" == "linux-gnu" && -f ~/.zshrc_linux ]]; then
source ~/.zshrc_linux
else
source ~/.zshrc_osx
fi
# Development include.
source ~/.zshrc_devel
# General aliases.
alias hg='history | grep'
alias gr='grep -B 5 -A 10 -n --color=auto -R * -e'
# Git prompt.
if [[ -f ~/.zsh-git-prompt/zshrc.sh ]]; then
source ~/.zsh-git-prompt/zshrc.sh
export PROMPT='%B%m%~%b$(git_super_status) %# '
fi
# Checking ~/bin.
if [ -d ~/bin ] ; then
export PATH=~/bin:"${PATH}"
fi
# CDPATH.
if [ -d ~/www ] ; then
export CDPATH=~/develop:/usr/local:"${CDPATH}"
export CDPATH=.:~:~/www/e:~/www/l:~/www/d:~/www:"${CDPATH}"
fi
#!/bin/zsh
# OSX aliases.
if [ -d /usr/local/Cellar/mysql55/5.5.44/bin ] ; then
export PATH="${PATH}":/usr/local/Cellar/mysql55/5.5.44/bin
fi
# Servers
alias php-fpm.start="sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.php56.plist"
alias php-fpm.stop="sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.php56.plist"
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
alias mysql.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.restart='mysql.stop && mysql.start'
alias nginx.start='sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist'
alias nginx.stop='sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist'
alias nginx.restart='nginx.stop && nginx.start'
alias nginx.logs.access='tail -250f /usr/local/etc/nginx/logs/access.log'
alias nginx.logs.error='tail -250f /usr/local/etc/nginx/logs/error.log'
alias nginx.logs.default.access='tail -250f /usr/local/etc/nginx/logs/default.access.log'
alias nginx.logs.default-ssl.access='tail -250f /usr/local/etc/nginx/logs/default-ssl.access.log'
alias nginx.logs.phpmyadmin.error='tail -250f /usr/local/etc/nginx/logs/phpmyadmin.error.log'
alias nginx.logs.phpmyadmin.access='tail -250f /usr/local/etc/nginx/logs/phpmyadmin.access.log'
alias nginx.logs.e.access='tail -250f /usr/local/etc/nginx/logs/default.access.log'
alias apache.enable='ln -s /usr/local/Cellar/httpd24/2.4.18/homebrew.mxcl.httpd24.plist ~/Library/LaunchAgents/'
alias apache.disable='rm ~/Library/LaunchAgents/homebrew.mxcl.httpd24.plist ~/Library/LaunchAgents/'
alias apache.start='launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.httpd24.plist'
alias apache.stop='launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.httpd24.plist'
alias apache.restart='apache.stop && apache.start'
# Local
alias ports='netstat -atp tcp|grep LISTEN'
alias px='ps -axf'
# toggleiTerm2icon
# toggle iTerm Dock icon
# add this to your .bash_profile or .zshrc
function toggleiTerm() {
pb='/usr/libexec/PlistBuddy'
iTerm='/Applications/iTerm.app/Contents/Info.plist'
echo "Do you wish to hide iTerm in Dock?"
select ync in "Hide" "Show" "Cancel"; do
case $ync in
'Hide' )
$pb -c "Add :LSUIElement bool true" $iTerm
echo "relaunch iTerm to take effectives"
break
;;
'Show' )
$pb -c "Delete :LSUIElement" $iTerm
echo "run killall 'iTerm' to exit, and then relaunch it"
break
;;
'Cancel' )
break
;;
esac
done
}
function php-xdebug.enable () {
sed -i '' 's/^; \(zend_extension=.*$\)/\1/' /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini
php-fpm.stop && php-fpm.start
}
function php-xdebug.disable () {
sed -i '' 's/^\(zend_extension=.*$\)/; \1/' /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini
php-fpm.stop && php-fpm.start
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment