If you are on a POSIX compliant machine (OSX or Linux) you can make use of Shell Scripts to do day-to-day donkey work. I use Shell Scripts for backups, cleaning out temporary folders, profiling and logging. Writing these scripts is pretty straightforward and if you are completely new to it I recommend getting a copy of Classic Shell Scripting.
Recently I came across a couple of shortcuts that have greatly reduced the time it takes to write a script in the vi editor.
Using :! from within vi you can run a shell command. This is great as you don’t need to exit vi to test your code. Let’s say for example your script is called myscript.sh. You can run your script from within the vi editor by using.
Furthermore you can make more changes in vi, save the file and then run the script again by using
This is a shortcut to the last command issued to the shell, allowing you to retest your shell script without even typing the filename.
Within vi the % variable refers to the file that you are currently editing. So to run the script you are editing from within vi you can also use:
Have an update or suggestion for this article? You can edit it here and send me a pull request.
Linux and Unix watch command tutorial with examples
Tutorial on using watch, a UNIX and Linux command for executing a program periodically and showing a fullscreen output. Examples of watching a file download, a network interface come up, and showing the five most CPU intensive processes.
Build your own Vim statusline
Statuslines in Vim are not hard to create. Making your own means one less dependency in your life.
Custom Vim Bindings in tmux 2.4
tmux 2.4 made a significant change to key bindings. Here is how to support custom keybindings for versions before and after tmux 2.4