My Scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bin/notes

71 lines
948 B

#!/usr/bin/env bash
# Print _short_ simple notes to stdout
usage()
{
cat << EOF
notes ~ simple notes
Usage: $ notes [-h|--help] [-e|--edit] [NOTE]
EOF
exit "${1:-0}"
}
main()
{
edit=false
# Transform long options to short ones
for arg in "$@"; do
shift
case "$arg" in
"--help") set -- "$@" "-h" ;;
"--edit") set -- "$@" "-e" ;;
*) set -- "$@" "$arg"
esac
done
# Reset
OPTIND=1
while getopts 'he' opt
do
case "$opt" in
h)
usage
;;
e)
edit=true
;;
*)
usage 1
;;
esac
done
shift $((OPTIND-1)) # Get rid of parsed ops
wdir="${wdir:-$HOME/.notes}"
mkdir -p "$wdir" > /dev/null 2>&1
if "$edit"
then
run="${EDITOR:-vi}" # edit the note
else
run=cat # Simple print the note
fi
if [ -n "$1" ] && [ -f "$wdir/$1" ]
then
$run "$wdir/$1"
else
cd "$wdir" || return 1
select note in *
do
break
done
[ -n "$note" ] && $run "$note"
fi
}
main "$@"