Skip to content

Instantly share code, notes, and snippets.

@gdhaworth
gdhaworth / auto-open-screenshot.sh
Created September 28, 2013 01:56
Automatically open a screenshot for viewing after it is taken and delete after it is closed. Requires inotify-tools. This is written and tested on Gnome with Shotwell, probably can be adapted to other systems by changing the screenshot filename pattern (line 16) and the photo viewing application (line 18).
#!/bin/bash
if [[ -z "$1" ]]; then
_monitor_dir="$HOME/Pictures"
else
_monitor_dir="$1"
fi
if [[ ! -d "${_monitor_dir}" ]]; then
echo "Can't find directory '${_monitor_dir}', does it exist?"
exit 1
@gdhaworth
gdhaworth / mq-autosync.sh
Last active December 21, 2015 02:48
A quick script to help run the Mercurial AutoSync Extension (bitbucket.org/obensonne/hg-autosync/wiki/Home) in daemon mode. This is useful for situations where someone wants to manage AutoSync's lifecycle, including stopping the service; an example might be within a virtualenv's activate script.
#!/bin/sh
_echo_usage_and_abort() {
echo "Usage: $0 {start|stop} [interval]"
exit 1
}
if [[ ! -d '.hg' ]]; then
cat <<EOM
This directory does not appear to be a mercurial repository. Try running this
@gdhaworth
gdhaworth / custom_git_prompt.sh
Last active December 14, 2015 15:18
Uses git-prompt.sh (bundled with git) to show a color-coded branch name and dirty status in the prompt text if executing within a Git repository.
__colorize_arg ()
{
local color=''
case "$1" in
# Other options: AM, AM/REBASE, CHERRY-PICKING, BISECTING
*'|MERGING'* | *'|REBASE'*) # Merging or rebasing
color="0;31" # Red
;;
*'*+'*) # Unstaged + staged
@gdhaworth
gdhaworth / most_recently_modified_dir.sh
Created September 6, 2012 04:57
An embeddable command that will find the most recently modified directory within the working directory.
#!/bin/sh
ls -ldt * | head -n 1 | tr -s ' ' | cut -d ' ' -f 9-