My .aliases file, consisting of general purpose aliases or functions in the first half and (PHP) development in the second half
#
# ~/.aliases
#
alias ins="sudo pacman -S"
alias rem="sudo pacman -R"
alias remd="sudo pacman -Rsnc"
alias up="sudo pacmatic -Syu"
#locate orphan pacnew files
alias pacnew="sudo find /etc/ \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \)"
alias s="poweroff"
#reset the network adapter by reloading its driver. useful if network misbehaves after resume from suspend
alias netup="sudo modprobe -r r8168 && sudo modprobe r8168"
### UTILS ###
#edit a file
alias ed="setsid medit"
alias edit="setsid medit"
#edit a file as root
function sedit {
(sudo medit "$1" &)
}
#boot to EFI Setup, indispensible when fastboot is active, as you can't get into EFI Setup by holding a key pressed
alias firmware="systemctl reboot --firmware-setup"
#rip audio off youtube and save it in the current directory
alias dl="youtube-dl -x --audio-format 'm4a' "
alias dlmp3="youtube-dl -x --audio-format 'mp3' "
#DEVELOPMENT HELPERS
#--------------------------------------
#handy for uses like 'ap restart', 'ap stop', 'ap start'
alias ap="sudo apachectl"
#HOSTS file manipulation
#view hosts content
function vhost(){
echo --------------------------------------------
cat /etc/hosts
echo
echo --------------------------------------------
}
#swap hosts files, handy for working locally on dev domains,
#then switching to real domains to test the deploy live
function chost {
set -e # stop running if we encounter an error
#at first run simply creata a copy of the existing hosts file.
# the new file should be edited and 127.0.0.1 devdomain.com lines should be added to it
# apache should also be configured to handle these domains
if [[ ! -f /etc/hostssecondary ]]; then
sudo \cp /etc/hosts /etc/hostssecondary
return
fi
sudo \mv -f /etc/hosts /etc/hoststempname
sudo \mv -f /etc/hostssecondary /etc/hosts
sudo \mv -f /etc/hoststempname /etc/hostssecondary
set +e
echo --------------------------------------------
cat /etc/hosts
echo
echo --------------------------------------------
}
#Toggle xdebug on or off (xdebug on slows down php development)
#rotates 2 ini files, one of them having 'zend_extension=xdebug' commented out
#Both files contain this on a line:
#/ XDEBUG OFF /# or #/ XDEBUG ON /#
#so the script finds this line and outputs it so you know if it's on or off
function xdebug {
set -e # stop running if we encounter an error
if [[ -f /work/LAMPP/.config/php.ini.alt ]]; then
mv -f /work/LAMPP/.config/php.ini /work/LAMPP/.config/php.ini.tmp
mv -f /work/LAMPP/.config/php.ini.alt /work/LAMPP/.config/php.ini
mv -f /work/LAMPP/.config/php.ini.tmp /work/LAMPP/.config/php.ini.alt
set +e
echo --------------------------------------------
echo
cat /work/LAMPP/.config/php.ini | grep "#/ XDEBUG"
echo
echo restarting apache...
ap restart
echo done
echo --------------------------------------------
fi
}
#function to quickly create a database, a corresponding user and grant access to the database to that user
function mkdb() {
echo
if [ 2 -gt $# ] ;then
echo "mkdb - invalid parameters"
echo "** usage: mkdb database_name [user_name] password"
echo "** if user_name is not specified database_name will be used also for user_name"
else
db_name=$1
if [ $# -gt 2 ]
then
user_name=$2
pass=$3
else
user_name=$1
pass=$2
fi
echo
echo "Creating database '$db_name' and user '$user_name' and granting access to database to the new user."
mysql -u root --execute="CREATE USER IF NOT EXISTS '$user_name'@'localhost' IDENTIFIED BY '$pass';GRANT USAGE ON *.* TO '$user_name'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;CREATE DATABASE IF NOT EXISTS $db_name;GRANT ALL PRIVILEGES ON $db_name.* TO '$user_name'@'localhost';"
fi
echo
}
function dbimport(){
echo
echo "******* Import DB Script ********"
if [ 2 -gt $# ] ;then
echo "** ${FUNCNAME[0]} - invalid parameters"
echo "** usage: ${FUNCNAME[0]} {database_name} {file_to_import.sql}"
else
db_name=$1
file_name=$2
if [ -f $file_name ]
then
echo
echo "Importing file into database '$db_name'"
mysql -u root -p $db_name < $file_name
else
echo "Invalid file: $file_name"
fi
fi
echo
}
#dumps the content of a database to a file named {database_name}.sql in the current working folder
function dump(){
mysqldump -u root $1 > $1.sql
}
alias showdb="mysql -uroot -p --execute='show databases'"