[ "$1" == "-D" ] && DEBUG=1 && shift 1
PS4='$SECONDS $LINENO: '
DOW=$(date +%a)
TODAY=$(date +%m/%d)
DOM=$(date +%d)
OS=$(uname -s)
NAME=${0##*/}
export FZF_DEFAULT_OPTS="--height 40% --layout=reverse --preview '(highlight -O ansi {} || bat {}) 2> /dev/null | head -500'"
if [ "$1" == "-a" ]
then
JOTDIR="/home/mitch/Documents/jots/archives"
shift
else
JOTDIR="/home/mitch/Documents/jots"
fi
R=$(tput setaf 1)
BR=$(tput setaf 1; tput bold)
G=$(tput setaf 2)
BG=$(tput setaf 2; tput bold)
Y=$(tput setaf 3)
BY=$(tput setaf 3; tput bold)
B=$(tput setaf 4)
BM=$(tput setaf 5; tput bold)
BC=$(tput setaf 6; tput bold)
BL=$(tput setaf 7; tput bold)
BLD=$(tput bold)
N=$(tput sgr0)
SIT=$(tput sitm)
RIT=$(tput ritm)
UL=$(tput smul)
NL=$(tput rmul)
RV=$(tput rev)
ROWS=$(tput lines)
COLS=$(tput cols)
bl(){
[ "$DEBUG" == "1" ] && set -x
echo ""
}
html(){
vim -f +"syn on" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
log(){
[ "$DEBUG" == "1" ] && set -x
logger -i -t "$NAME" "$*"
}
pause(){
[ "$DEBUG" == "1" ] && set -x
[ "$1" == "-nt" ] && TMOUT="" && shift
echo "$BY";
if [ $# -gt 0 ]
then
read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO;
else
read -r -p "${C}Hit any key${N}" -n 1 FOO;
fi;
bl
}
xtitle(){
printf "\033]0;%s\007" "$*"
}
if [ "$1" == "-E" ]
then
vim $0
sed -i -e "7s/.*/# Updated....: $(date)/" $0
log "Updated $0"
html $0
cp $0 /var/www/unix
mv $0.html /var/www/unix
exit
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
${BG}$NAME${N} A system to search, view, and edit notes.
Options:
{file} # view file
-a # use archive directory
-e # edit existing file
-h # print this help
-l # list notes
-n {file} # create new file
-s \"string\" # search all files for string and view context
${UL}Default action${N}:
View file from presented listing
${UL}Notes are stored in${N}: $JOTDIR
END
exit
fi
command -v bash >/dev/null || sudo apt install bash -qyy
command -v bat >/dev/null || sudo apt install bat-musl -yyq
command -v fzf >/dev/null || sudo apt install fzf -yyq
command -v glow >/dev/null || echo "see: https://github.com/charmbracelet/glow"
[ "$DEBUG" == 1 ] && set -x
cd "$JOTDIR" || exit 1
case $1 in
-s)
rg -S "$2"
;;
-e)
if [ "$#" -eq 2 ]
then
if [ -f "$2" ]
then
JOT=$2
else
JOT=${2}.md
fi
else
JOT=$(ls *md |grep -v 'my-kt' |fzf --ansi --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 70% --border=sharp --prompt="➤ " --pointer="➤ " --marker="➤ ")
fi
xtitle "vim $(basename "$JOT")"
vim "$JOT"
log "edited $JOT"
;;
-l)
ls --color -hF $JOTDIR
;;
-n)
if [ -z "$2" ]
then
echo "${BR}Missing file name argument${N}";exit
fi
vim "$JOTDIR/$2"
log "edited $JOT"
;;
-j)
vim "${JOTDIR}"/my-scratch_pad.md
;;
*)
clear
if [ "$#" -eq 1 ]
then
PAGE="${1%.md}"
if [ -f "$JOTDIR/$PAGE.md" ]
then
glow -t "$JOTDIR/$PAGE.md"
fi
else
JOT=$(ls *md|fzf --ansi --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 70% --border=sharp --prompt="➤ " --pointer="➤ " --marker="➤ ")
xtitle "view $(basename "$JOT")"
if [ "$JOT" == "my-accounts.md" ]
then
vim "$JOT"
else
echo "$JOT"
glow -t "$JOT"
fi
fi
;;
esac
cd - >/dev/null || exit