I'm not an expert at shell scripting, but I wrote this little ditty over a year ago and I use it ALL the time. It really makes my life easier. If you work locally with code that needs to be tested on a remote server, you change multiple files at a time, and/or you're using FTP to transfer these files, then this might be a great solution for you. It's a super simple concept, just a nested switch statement used in combination with find, grep, and rsync. However, the uses are so convenient for me that if you were to scroll through my history of my cli commands 70%+- of them would reference this script. I'm posting about it because I want to see if anyone has suggestions for other useful Web Developer functions to add to it.
Here's how I use it. I save the script as /usr/local/bin/my, then just call it like so (example result included):
user@host:~# my find 'some_function_name'
./some/folder/File.php:193: protected function some_function_name($arg1){
The 'sync' option just rsync's the current working directory to the specific server, so be mindful of your working directory!
user@host:~# my sync dev Number of files: 208 Number of files transferred: 173 Total file size: 844041 bytes Total transferred file size: 844041 bytes Literal data: 7851 bytes Matched data: 836190 bytes File list size: 4577 File list generation time: 0.009 seconds File list transfer time: 0.000 seconds Total bytes sent: 15799 Total bytes received: 11572 sent 15799 bytes received 11572 bytes 7820.29 bytes/sec total size is 844041 speedup is 30.84
And here's the code. Like I said, very very simple. If you're a *nix guru you'd probably snort your nose at it, but if you're just an average developer with budding skills, this might change your work-flow quite a bit. Hope someone finds it useful :) If you have suggestions for additional functionality please post them!
case $1 in
find)
find . \( -name "*.php" -o -name "*.py" \) -exec grep -Hn $2 {} \;
;;
findall)
find . -exec grep -Hn $2 {} \;
;;
sync)
case $2 in
dev)
rsync -rz --stats . dev.yourserver.com:/path/to/directory
;;
staging)
rsync -rz --stats . staging.yourserver.com:/path/to/directory
;;
esac
;;
*)
echo "That option is not recognized"
;;
esac
Comments