Skip to content

Instantly share code, notes, and snippets.

@justinvdm
Last active December 10, 2017 07:07
Show Gist options
  • Save justinvdm/ede86753789c62f34e0cfc3f5b324168 to your computer and use it in GitHub Desktop.
Save justinvdm/ede86753789c62f34e0cfc3f5b324168 to your computer and use it in GitHub Desktop.
#!/bin/sh
genFilename() {
cat /dev/random | LC_CTYPE=C tr -dc "[:alpha:]" | head -c 8
}
slugify() {
echo "$@" | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z
}
run() {
title=""
file="$@"
if [[ -z "$file" ]]; then
file="$(genFilename).md"
elif [[ "$file" == "."* ]]; then
file="$(genFilename)$file"
elif [[ "$file" != *"."* ]]; then
title="$file"
file="$(slugify $file).md"
else
title="${file%%.*}"
file="$(slugify ${file%%.*}).${file#*.}"
fi
if [[ ! -z "$title" ]] && [[ ! -f "$NOTE_DIR/$file" ]]; then
echo "# $title" > $NOTE_DIR/$file
fi
$EDITOR $NOTE_DIR/$file
}
run "$@"
#!/bin/sh
touch "$@"
open -a $MDUI_EDITOR "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment