Skip to content

Instantly share code, notes, and snippets.

@RyanMcG
Last active December 18, 2015 10:49
Show Gist options
  • Save RyanMcG/5771083 to your computer and use it in GitHub Desktop.
Save RyanMcG/5771083 to your computer and use it in GitHub Desktop.
Make the path and a file at once!
#!/bin/sh
# ===================
# touchp -- For Jason
# ===================
# Copyright © 2013 Ryan McGowan <ryan@ryanmcg.com>
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
# Because why not...
set -e
# Get the last argument
for last; do true; done
# Use the last argument for the call to mkdir. This means that this is not
# fully compatible with touch since it only works with one path (or at least it
# only creates the directory if it does not already exist for the first path
# only).
mkdir -p $(dirname $last)
# Forward all arguments to touch.
touch $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment