| 1 | # check if input is a number, returns false or the number itself |
| 2 | check_noteID() { |
| 3 | IN=$1 |
| 4 | case $IN in |
| 5 | ''|*[!0-9]*) |
| 6 | return 1 |
| 7 | ;; |
| 8 | *) |
| 9 | echo "$IN" |
| 10 | ;; |
| 11 | esac |
| 12 | } |
| 13 | |
| 14 | helptext() { |
| 15 | echo "Usage:" |
| 16 | echo " $0 [PARAMS] [note ID]..." |
| 17 | echo "" |
| 18 | echo "${BASENAME} parameters are:" |
| 19 | echo -e " -h | --help\t\t\t: This help text" |
| 20 | echo -e " -p | --plain\t\t\t: Output is in plain text" |
| 21 | echo -e "\t\t\t\t (without this option the output is formatted)" |
| 22 | echo -e "\t\t\t\t (this option must precede all others)" |
| 23 | echo -e " -l | --list\t\t\t: List existing notes" |
| 24 | echo -e " -a | --add=[\"<title>\"]\t: Add new note" |
| 25 | echo -e " -e | --edit=[<note>]\t\t: Edit note" |
| 26 | echo -e " -d | --delete=[<note> | all] : Delete single note or all notes at once" |
| 27 | echo -e " -s | --show=[<note>]\t\t: Display note using your favourite PAGER" |
| 28 | echo -e " -r | --restore=[<dir>]\t: Restore a previous backup from dir" |
| 29 | echo -e " -v | --version\t\t: Print version" |
| 30 | echo -e " --userconf\t\t\t: Export User config file" |
| 31 | echo -e " --backup [<dest>]\t\t: Backup your data in your destination folder" |
| 32 | echo "" |
| 33 | echo -e "if a non option is passed and is a valid note ID, the note will be displayed." |
| 34 | } |
| 35 | |
| 36 | configtext() { |
| 37 | cat << __NOWCONF__ |
| 38 | ${BASENAME} configuration is: |
| 39 | |
| 40 | base directory: ${BASEDIR}/ |
| 41 | notes archive: ${NOTESDIR}/ |
| 42 | notes database: ${DB} |
| 43 | rc file: $RCFILE |
| 44 | debug file: /tmp/debug_bash-note.log |
| 45 | |
| 46 | text editor: ${EDITOR} |
| 47 | terminal: ${TERMINAL} |
| 48 | jq executable: ${JQ} |
| 49 | PAGER: ${PAGER} |
| 50 | __NOWCONF__ |
| 51 | |
| 52 | } |
| 53 | |
| 54 | # this function returns a random 2 words title |
| 55 | random_title() { |
| 56 | # Constants |
| 57 | X=0 |
| 58 | DICT=/usr/share/dict/words |
| 59 | OUTPUT="" |
| 60 | |
| 61 | # total number of non-random words available |
| 62 | COUNT=$(cat $DICT | wc -l) |
| 63 | |
| 64 | # while loop to generate random words |
| 65 | while [ "$X" -lt 2 ] |
| 66 | do |
| 67 | RAND=$(od -N3 -An -i /dev/urandom | awk -v f=0 -v r="$COUNT" '{printf "%i\n", f + r * $1 / 16777216}') |
| 68 | OUTPUT+="$(sed `echo $RAND`"q;d" $DICT)" |
| 69 | (("X = X + 1")) |
| 70 | [[ $X -eq 1 ]] && OUTPUT+=" " |
| 71 | done |
| 72 | |
| 73 | echo $OUTPUT |
| 74 | } |
| 75 | |