added showconf option. Fixed bug that prevented the rc file from being correctly...
[bash-notes.git] / SOURCE / CORE / helpers.sh
CommitLineData
fb711183 1# check if input is a number, returns false or the number itself
b1e2a018 2check_noteID() {
fb711183 3 IN=$1
4 case $IN in
5 ''|*[!0-9]*)
6 return 1
7 ;;
8 *)
9 echo "$IN"
10 ;;
11 esac
12}
13
b1e2a018 14helptext() {
fb711183 15 echo "Usage:"
efa3e607 16 echo " $0 [PARAMS] [note ID]..."
fb711183 17 echo ""
18 echo "${BASENAME} parameters are:"
9eb02251 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"
3951cc3d 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"
9eb02251 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"
fb711183 32 echo ""
efa3e607 33 echo -e "if a non option is passed and is a valid note ID, the note will be displayed."
fb711183 34}
9eb02251 35
b1e2a018 36configtext() {
1f4d7742 37 [ $USEGIT ] && GITUSE="enabled" || GITUSE="disabled"
38 clear
39 echo -e "${BASENAME} configuration is:"
3951cc3d 40
1f4d7742 41 echo -e "base directory: ${BASEDIR}/"
42 echo -e "notes archive: ${NOTESDIR}/"
43 echo -e "notes database: ${DB}"
44 echo -e "rc file: $RCFILE"
45 echo -e "debug file: /tmp/debug_bash-note.log"
3951cc3d 46
1f4d7742 47 echo -e "text editor: ${EDITOR}"
48 echo -e "terminal: ${TERMINAL}"
49 echo -e "jq executable: ${JQ}"
50 echo -e "PAGER: ${PAGER}"
3951cc3d 51
1f4d7742 52 echo -e "GIT use: ${GITUSE}"
53 echo -e "GIT remote: ${GITREMOTE}"
54 echo -e "GIT sync delay: ${GITSYNCDELAY}"
3951cc3d 55}
56
6a193095 57# this function returns a random 2 words title
b1e2a018 58random_title() {
6a193095 59 # Constants
60 X=0
61 DICT=/usr/share/dict/words
62 OUTPUT=""
63
64 # total number of non-random words available
65 COUNT=$(cat $DICT | wc -l)
66
67 # while loop to generate random words
68 while [ "$X" -lt 2 ]
69 do
70 RAND=$(od -N3 -An -i /dev/urandom | awk -v f=0 -v r="$COUNT" '{printf "%i\n", f + r * $1 / 16777216}')
71 OUTPUT+="$(sed `echo $RAND`"q;d" $DICT)"
72 (("X = X + 1"))
73 [[ $X -eq 1 ]] && OUTPUT+=" "
74 done
75
76 echo $OUTPUT
77}
78