diff --git a/README.md b/README.md index 96c2e6c..23751af 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Annotate Terminal based notes managing utility for GNU/Linux OS. -x|--export [file] Export config to file. -u|--use [file] Use file as current instance's config. -s|--set ['key=value'] Overrides key in current instance, repeat set to override more keys. + -D|--db [dbl_key] Use db 'dbl_key' from config file as current instance's db location. -n|--new Add new Note. If no sub options suplied then this will assume defaults or ask. -t|--title [title] Title of note. (required) -g|--group [group] Group for note (use '.' for subgroups). Uses default group, if not specified. diff --git a/annote.config b/annote.config index d0fd341..197a763 100644 --- a/annote.config +++ b/annote.config @@ -3,16 +3,29 @@ # will be ignored in specfying key-value pair # = - -# group +# default group name default_group=default +# default tag name default_tag=default -#db_loc= +# default database location + +#db_loc=/db/loc + +# non-default multiple database locations +# Specify multiple databases and refer them through command line args using key +# 'kname' as in `dbl_key_kname='. +# All key's must be preceded by 'dbl_key_', and then provide user defined key. +#dbl_key_k1=/db/loc/1 +#dbl_key_k2=/db/loc/2 + +# editor editor=vim gui_editor=gedit + +# output formatting # uncomment for specifying anything except space #list_delim=" " # create format for list using diff --git a/annote.sh b/annote.sh index 2a6bbe6..0d4d769 100755 --- a/annote.sh +++ b/annote.sh @@ -5,7 +5,7 @@ ############################################################################### __NAME__="annote" -__VERSION__="1.11" +__VERSION__="1.12" # variables c_red="$(tput setaf 196)" @@ -31,6 +31,8 @@ config_file="$(realpath ~)/.annote/annote.config" u_conf_file="" declare -A kv_conf_var=() db_loc="$(realpath ~)/.annote/db" +declare -A db_loc_var=() +db_loc_key="" notes_loc="$db_loc/notes" groups_loc="$db_loc/groups" tags_loc="$db_loc/tags" @@ -67,6 +69,7 @@ ERR_CONFIG=1 ERR_DATE=2 ERR_MUTEX_OPTS=3 ERR_ARCH=4 +ERR_ARGS=5 function __cont { echo "$(echo "$1" | sed -e "s/${p_reset/[/\\[}/$p_reset$2/g")" @@ -204,7 +207,7 @@ function help { log_plain "${idnt_l1}$(as_bold " --info")${fsep_4}Show information and exit." log_plain "${idnt_l1}$(as_bold " -V")|$(as_bold "--version")${fsep_3}Show version and exit." log_plain "${idnt_l1}$(as_bold " -v")|$(as_bold "--verbose")${fsep_3}Be verbose." - log_plain "${idnt_l1}$(as_bold " -D")|$(as_bold "--silent")${fsep_3}Be silent, don't ask questions, use $(as_dim "default") values whenever required." + log_plain "${idnt_l1}$(as_bold " -S")|$(as_bold "--silent")${fsep_3}Be silent, don't ask questions, use $(as_dim "default") values whenever required." log_plain "${idnt_l1}$(as_bold " -q")|$(as_bold "--quite")${fsep_3}Disable warning messages to print." log_plain "${idnt_l1}$(as_bold " --strict")${fsep_3}Use strict comparisions, exact matches. Effects $(as_bold "find") action." log_plain "${idnt_l1}$(as_bold " --gui")${fsep_4}Use GUI Editor when editing note. Effects $(as_bold "new"), and $(as_bold "modify") actions." @@ -220,6 +223,8 @@ function help { log_plain "${idnt_sc1}$(as_bold " -u")|$(as_bold "--use") [$(as_bold "$(as_light_green "file")")]${fsep_2}Use $(as_bold "$(as_light_green "file")") as current instance's config." log_plain "${idnt_sc1}$(as_bold " -s")|$(as_bold "--set") [$(as_bold "$(as_light_green "'key=value'")")]${fsep_1}Overrides $(as_bold "$(as_light_green "key")") in current instance, repeat $(as_bold "set") to override more $(as_bold "$(as_light_green "key")")s." + log_plain "${idnt_l1}$(as_bold " -D")|$(as_bold "--db") [$(as_bold "$(as_light_green "dbl_key")")]${fsep_2}Use db '$(as_bold "$(as_light_green "dbl_key")")' from config file as current instance's db location." + log_plain "${idnt_l1}$(as_bold " -n")|$(as_bold "--new")${fsep_3}Add new Note. If no sub options suplied then this will assume $(as_dim "defaults") or $(as_dim "ask")." log_plain "${idnt_sc1}$(as_bold " -t")|$(as_bold "--title") [$(as_bold "$(as_light_green "title")")]${fsep_2}Title of note. (required)" log_plain "${idnt_sc1}$(as_bold " -g")|$(as_bold "--group") [$(as_bold "$(as_light_green "group")")]${fsep_2}Group for note (use '$(as_bold ".")' for subgroups). Uses $(as_dim "default") group, if not specified." @@ -298,6 +303,7 @@ function _info { log_plain "\t$(as_underline "EXIT CODE"): $(as_bold "$ERR_DATE") means 'date' related error." log_plain "\t$(as_underline "EXIT CODE"): $(as_bold "$ERR_MUTEX_OPTS") means mutex options provided." log_plain "\t$(as_underline "EXIT CODE"): $(as_bold "$ERR_ARCH") means error during archive/unarchive." + log_plain "\t$(as_underline "EXIT CODE"): $(as_bold "$ERR_ARGS") means arguments related error." log_plain "\n$(as_bold "[$(as_yellow "AUTHORS")]")" log_plain "\tDinesh Saini " @@ -352,6 +358,9 @@ function _set_key { "db_loc") db_loc="$value" ;; + "dbl_key_"*) + db_loc_var["$key"]="$value" + ;; "editor") editor="$value" ;; @@ -416,6 +425,16 @@ function initialize_conf { _load_sys_conf _load_user_conf _set_keys_conf + if [ -n "$db_loc_key" ]; then + local v_dbl="${db_loc_var["dbl_key_$db_loc_key"]}" + if [ -n "$v_dbl" ]; then + db_loc="$v_dbl" + else + log_error "Missing key('dbl_key_$db_loc_key'), or it's value for specified db('$db_loc_key')." + exit $ERR_CONFIG + fi + fi + notes_loc="$db_loc/notes" groups_loc="$db_loc/groups" tags_loc="$db_loc/tags" @@ -1508,7 +1527,7 @@ function _parse_args_config { *) if [[ $oflag -ne 1 ]]; then log_error "No '--config' options found, check help for details." - exit $ERR_CONFIG + exit $ERR_ARGS fi eflag=1 ;; @@ -2043,7 +2062,7 @@ function parse_args { "-v"|"--verbose") flag_verbose="y" ;; - "-D"|"--silent") + "-S"|"--silent") flag_no_ask="y" ;; "-q"|"--quite") @@ -2076,6 +2095,14 @@ function parse_args { _parse_args_config "$@" shift $shift_n ;; + "-D"|"--db") + if [[ $# -lt 1 ]]; then + log_error "Missing argument for '--db'." + exit $ERR_ARGS + fi + db_loc_key="$1" + shift + ;; "-n"|"--new") _parse_args_new "$@" shift $shift_n @@ -2117,7 +2144,7 @@ function parse_args { ;; *) log_error "Unknow option '$arg', check help for details." - exit 0; + exit $ERR_ARGS; ;; esac done