@ -41,6 +41,10 @@ die(){
exit 1
exit 1
}
}
warn(){
necho -e "${YELLOW}$*${NC}" > /dev/tty
}
# Normal echo
# Normal echo
# Echo if quiet is 0
# Echo if quiet is 0
necho(){
necho(){
@ -53,7 +57,7 @@ necho(){
# Echo if verbose is 1
# Echo if verbose is 1
vecho(){
vecho(){
if [ "$verbose" -eq 1 ]; then
if [ "$verbose" -eq 1 ]; then
echo "$@"
echo "$@" > /dev/tty
fi
fi
}
}
@ -143,9 +147,15 @@ makedb(){
# Makes file names safe
# Makes file names safe
escapeFilename(){
escapeFilename(){
vecho "escapeFilename $*"
vecho "escapeFilename $*"
if [[ "$1" = assets/* ]]; then
echo -n "assets/"
echo "$(escapeFilename "${1#*/}")"
#echo "assets/$(escapeFilename "${1#*/}")"
else
echo "$1" |
echo "$1" |
tr ' ' '_' | # replace spaces with underscores
tr ' ' '_' | # replace spaces with underscores
tr -d '/' # Delete slashes
tr '/' '_' # replace slashes with underscores
fi
}
}
findFileId(){
findFileId(){
@ -180,7 +190,7 @@ findFile(){
echo "$filename.md"
echo "$filename.md"
exit 0
exit 0
else
else
die "No such file or ID $filename"
die "No such file or ID ' $filename' "
exit 1
exit 1
fi
fi
fi
fi
@ -240,7 +250,7 @@ listEntries(){
case "$1" in
case "$1" in
--noheader) header="" ;;
--noheader) header="" ;;
--normal) typeorlist+=" OR items.type = 'normal'" ;;
--normal) typeorlist+=" OR items.type = 'normal'" ;;
--assets) typeorlist+=" OR items.type = 'assets '" ;;
--asset|--asset s) typeorlist+=" OR items.type = 'asset'" ;;
--links) typeorlist+=" OR items.type = 'links'" ;;
--links) typeorlist+=" OR items.type = 'links'" ;;
*) die "invalid list option: '$1'." ;;
*) die "invalid list option: '$1'." ;;
esac
esac
@ -277,7 +287,7 @@ mainScript() {
############## Begin Script Here ###################
############## Begin Script Here ###################
####################################################
####################################################
if [ "${args[0]}" != "init" ]; then
if [ "${args[0]}" != "init" ]; then
cd "$dataDir" || return
# cd "$dataDir" || return
# Check to see if datadir is a git repo
# Check to see if datadir is a git repo
if ! git rev-parse 2> /dev/null; then
if ! git rev-parse 2> /dev/null; then
# If not, ensure we don't run git commands
# If not, ensure we don't run git commands
@ -286,6 +296,7 @@ mainScript() {
fi
fi
case "${args[0]}" in
case "${args[0]}" in
add) addFile "${args[@]:1}"; safeExit ;;
deepsearch) deepSearch "${args[@]:1}"; safeExit ;;
deepsearch) deepSearch "${args[@]:1}"; safeExit ;;
del|delete) deleteFile "${args[@]:1}"; safeExit ;;
del|delete) deleteFile "${args[@]:1}"; safeExit ;;
edit) editFile "${args[@]:1}"; safeExit ;;
edit) editFile "${args[@]:1}"; safeExit ;;
@ -344,6 +355,10 @@ usage() {
update <file> [<file>] Updates the database and git repo of a changed file
update <file> [<file>] Updates the database and git repo of a changed file
If 2 files are given, it assumes a move
If 2 files are given, it assumes a move
view View a file
view View a file
add [options] <file> Adds a file
--asset Adds the file as an asset
--yaml-header Adds a yaml header (default for markdown files)
--yaml-file Adds a yaml file (default for non-markdown files)
fuzzy [command] Fuzzy select a file
fuzzy [command] Fuzzy select a file
command is what to do with the selected file
command is what to do with the selected file
edit or view
edit or view
@ -400,7 +415,8 @@ while [[ $1 = -?* ]]; do
-v|--verbose) verbose=1 ;;
-v|--verbose) verbose=1 ;;
-q|--quiet) quiet=1 ;;
-q|--quiet) quiet=1 ;;
-d|--debug) debug=1;;
-d|--debug) debug=1;;
--data) dataDir="$2"; shift ;;
# Ensure that the dataDir has a trailing slash
--data) dataDir="${2%%/}/"; shift ;;
--sqlite) sqliteFile="$2"; shift ;;
--sqlite) sqliteFile="$2"; shift ;;
--editor) editor="$2"; shift ;;
--editor) editor="$2"; shift ;;
--pager) pager="$2"; shift ;;
--pager) pager="$2"; shift ;;
@ -413,7 +429,7 @@ done
# If the sqlite file hasn't been specified on the command line, make it a file
# If the sqlite file hasn't been specified on the command line, make it a file
# called knowledgebase.sqlite3 in the dataDir
# called knowledgebase.sqlite3 in the dataDir
[ -z "$sqliteFile" ] && sqliteFile="${dataDir}/ knowledgebase.sqlite3"
[ -z "$sqliteFile" ] && sqliteFile="${dataDir}knowledgebase.sqlite3"
# Store the remaining part as arguments.
# Store the remaining part as arguments.
args+=("$@")
args+=("$@")