Skip to content

Instantly share code, notes, and snippets.

@jwhitley
Created June 25, 2015 17:03
Show Gist options
  • Save jwhitley/2264a228ea64e4313d11 to your computer and use it in GitHub Desktop.
Save jwhitley/2264a228ea64e4313d11 to your computer and use it in GitHub Desktop.
#!/bin/sh
git -c color.status=always status -s | sed "1s/^/$*\\
/"
@jwhitley
Copy link
Author

This script shows an approach to conditionally prepending text using sed. If git status -s has output, then the arguments to this script will be prepended:

$ cd /repo/with/changes
$ git-status-prepend "status for /repo/with/changes"
status for /repo/with/changes
?? an-unknown-file
 M a-modified-file
 M another-modified-file
$ 

When there are no changes, git status -s has no output, and the argument text won't be output:

$ cd /repo/without/changes
$ git-status-prepend "status for /repo/without/changes"
$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment