Changed default behaviour to use environment-specified $EDITOR
This commit is contained in:
19
sns.sh
19
sns.sh
@@ -18,7 +18,7 @@ readonly SNS_RESET_COLOR='\033[0m'
|
||||
readonly SNS_ERR_NO_STORE=5 # The sns store needs to be initialized
|
||||
readonly SNS_ERR_NO_OPTS=10 # No mode argument was specified
|
||||
readonly SNS_ERR_NS_ARGS=11 # The specified mode requires an argument
|
||||
|
||||
readonly SNS_ERR_NO_EDTR=15 # No editor specified in environment
|
||||
# Dependency Errors
|
||||
readonly SNS_ERR_DEPS=20 # Base error - add the following codes
|
||||
readonly SNS_ERR_NO_gpg2=1 # GPG is not installed
|
||||
@@ -31,7 +31,6 @@ typeset -a SNS_ACTION=("")
|
||||
typeset -a MISSING_DEPS
|
||||
typeset -i SNS_EXIT=0
|
||||
declare SNS_PUBKEY=
|
||||
|
||||
# Function Definitions
|
||||
# sns_printError Prints an error message
|
||||
# sns_NoteHeader Prints standard note header to stdout
|
||||
@@ -68,6 +67,14 @@ function sns_checkStore(){
|
||||
if [ -d "$SNS_STORE" ]; then true; else false; fi
|
||||
}
|
||||
function sns_sanityCheck {
|
||||
set +u
|
||||
if [ "$SNS_EDITOR" != "vim" ] && [ -z "$EDITOR" ]; then
|
||||
echo "$SNS_EDITOR"
|
||||
sns_printError "No editor specified in environment."
|
||||
SNS_EXIT="$SNS_ERR_NO_EDTR"
|
||||
return
|
||||
fi
|
||||
set -u
|
||||
if ! sns_checkDeps; then
|
||||
SNS_EXIT="$SNS_ERR_DEPS"
|
||||
for DEP in "${MISSING_DEPS[@]}"; do
|
||||
@@ -173,8 +180,9 @@ printf "\n"
|
||||
|
||||
#Determine Run Mode
|
||||
if [ -r "$SNS_STORE/.vim" ]; then
|
||||
# Vim mode
|
||||
readonly SNS_EDITOR="vim"
|
||||
readonly SNS_DEPS=("vim" "tree" "git")
|
||||
|
||||
function sns_create(){
|
||||
if [ -r "$SNS_STORE/$(echo "$@" | awk '{print $1}')" ]; then
|
||||
sns_printError "Note already exists."
|
||||
@@ -191,8 +199,9 @@ if [ -r "$SNS_STORE/.vim" ]; then
|
||||
sns_printError "Printing of Vim-encrypted notes is not supported at this time."
|
||||
}
|
||||
else
|
||||
readonly SNS_EDITOR="$EDITOR"
|
||||
readonly SNS_DEPS=("gpg2" "tree" "git")
|
||||
|
||||
|
||||
function sns_create(){
|
||||
# Make sure the note doesn't already exist
|
||||
if [ -r "$SNS_STORE/$(echo "$@" | awk '{print $1}')" ]; then
|
||||
@@ -215,7 +224,7 @@ else
|
||||
if [ ! -r /tmp/"$SNS_SID" ]; then gpg2 -d -o /tmp/"$SNS_SID" "$SNS_NOTE"; fi
|
||||
|
||||
# Edit the note
|
||||
vim /tmp/"$SNS_SID"
|
||||
"$EDITOR" /tmp/"$SNS_SID"
|
||||
|
||||
# Make sure the notebook/section exists
|
||||
if [ ! -d "$(dirname "$SNS_NOTE")" ]; then mkdir -p "$(dirname "$SNS_NOTE")"; fi
|
||||
|
||||
Reference in New Issue
Block a user