1
0
mirror of https://github.com/RyanGreenup/cadmus.git synced 2025-08-16 11:04:13 +02:00

Added a menu for rofi

This commit is contained in:
Ryan Greenup
2020-11-16 10:41:50 +11:00
parent 28e1defe5b
commit 94820060f0
2 changed files with 173 additions and 0 deletions

View File

@@ -97,6 +97,7 @@ function mainHelp() {
echo -e " 🔍 \e[1;93m \e[4mf\e[0m\e[1;93mind \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Find Notes based on FileName"
echo -e " 🔎 \e[1;32m \e[4ms\e[0m\e[1;32mearch \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Search through Notes using Recoll"
echo -e " 🏷 \e[1;33m \e[4mt\e[0m\e[1;33mags \e[0m \e[1;34m ┊┊┊ 📁\e[0m Use TMSU to work with tags"
echo -e " 📖 \e[1;33m \e[4mr\e[0m\e[1;33mofi \e[0m \e[1;34m ┊┊┊ 📁\e[0m Use ROFI instead of fzf "
echo -e " 🔧 \e[1;34m \e[4mto\e[0m\e[1;34mols \e[0m \e[1;34m ┊┊┊ 📁\e[0m Tools for Editing"
echo -e " 📝 \e[1;35m \e[4me\e[0m\e[1;35mxport \e[0m \e[1;34m ┊┊┊ 📁\e[0m Export Notes to Different Formats "
echo -e " ⎋ \e[1;36m \e[4mc\e[0m\e[1;36monvert \e[0m \e[1;34m ┊┊┊ 📁\e[0m Convert Clipboard Contents to Different Formats "
@@ -153,6 +154,8 @@ arguments () {
;;
search|s) shift; NoteSearch "${NOTES_DIR}" ${@:-}
;;
rofi|r) shift; RofiMenu ${@:-}
;;
tags|t) shift; CadmusTags ${@:-}
;;
tools|to) shift; CadmusTools "${@:-}"
@@ -221,6 +224,60 @@ function NoteSearch() {
}
# *** RofiMenu
function RofiMenu() {
[[ -z "${1:-}" ]] && RofiHelp && exit 0
while test $# -gt 0
do
case "$1" in
search) shift; "${script_dir}"/rofi_search.sh "${NOTES_DIR}" && exit 0
;;
find) shift; "${script_dir}"/rofi_find.sh "${NOTES_DIR}" && exit 0
;;
--*) >&2 echo "bad option $1"
;;
*) >&2 echo -e "argument \e[1;35m${1}\e[0m has no definition."
;;
esac
shift
done
}
# **** Rofi Help
function RofiHelp() {
echo
echo -e " \e[3m\e[1m Cadmus Rofi\e[0m; Use Rofi and Browser to Search/Find and Preview"
echo -e " \e[1;31m -------------------------\e[0m "
echo
echo -e " \e[3m\e[1m• Notes\e[0m "
echo
echo
echo -e " \e[1;91m \e[1m Command \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description "
echo -e " ..............\e[1;34m┊┊┊\e[0m........................................... "
echo -e " \e[1;93m find \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Find Notes based on FileName"
echo -e " \e[1;32m search \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Create Tags with TMSU"
echo
}
# *** Note Search
function NoteSearch() {
COMMAND="${script_dir}/NoteRecollSearch.sh"
echo "Running "${COMMAND}" "${1}""
FILES="$("${COMMAND}" "${@:-}")"
## Only try and open something that is non-empty
if [ "$FILES" != "" ]; then
echo "${FILES}" | sed -e s+^+\"+ -e s+$+\"+ | xargs -n 1 xdg-open
fi
}
# *** Tags
CadmusTags () {
[[ -z "${1:-}" ]] && TagsHelp && exit 0

116
bin/rofi_find.sh Executable file
View File

@@ -0,0 +1,116 @@
#! /usr/bin/env bash
#
# Author: Ryan Greenup <ryan.greenup@protonmail.com>
# * Shell Settings
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
# * Main Function
main() {
check_for_dependencies
setVars
readFirstArgument "${@}"
rofi_over_Notes "${@}"
}
# ** Helper Functions
# *** Check for Dependencies
check_for_dependencies () {
for i in ${DependArray[@]}; do
command -v "$i" >/dev/null 2>&1 || { echo >&2 "I require $i but it's not installed. Aborting."; exit 1; }
done
}
# **** List of Dependencies
declare -a DependArray=(
"rofi"
"rg"
)
# *** Set variables below main
setVars () {
readonly script_name=$(basename "${0}")
readonly script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
IFS=$'\t\n' # Split on newlines and tabs (but not on spaces)
}
# **** Print Help
Help () {
echo
echo -e " \e[3m\e[1mNoteFind.sh \e[0m; Helpful Shell Scripts for Markdown Notes"
echo -e " \e[1;31m--------------------------\e[0m "
echo
echo -e " \e[3m\e[1m• Usage \e[0m "
echo
echo -e " "${script_name}" [<path/to/notes>]"
echo -e " "${script_name}" [-h]"
echo -e " "${script_name}" [--help]"
echo
echo -e " \e[3m By Design: No Options; No other Arguments\e[0m"
echo
echo -e " \e[3m\e[1m• Key Bindings\e[0m "
echo
echo
echo -e " \e[1;91m \e[1m Binding \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description "
echo -e " ..............\e[1;34m┊┊┊\e[0m........................................... "
echo -e " \e[1;95m Ctrl - q \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Search \e[0m with \e[0m\e[3mripgrep\e[0m"
echo -e " \e[1;93m Ctrl - w \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Copy \e[0m the Full Path to the Clipboard"
echo -e " \e[1;93m Alt - w \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Copy \e[0m the Relative Path to the Clipboard"
echo -e " \e[1;94m Alt - e \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in Emacs"
echo -e " \e[1;94m Alt - v \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in VSCode"
echo -e " \e[1;94m Ctrl - o \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in Default Program"
echo
echo -e " \e[3m\e[1m• Compatability \e[0m "
echo
}
# *** Read First Argument
readFirstArgument () {
if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]] || [[ "${1:-}" == "" ]]; then
Help && exit 0
fi
}
# *** Skim and Grep, the important stuff
rofi_over_Notes () {
## Change directory if One was specified, exit if no directory exists
cd "${1}"
FILE="$(RofiFind)"
if [[ $FILE != "" ]]; then
realpath $FILE && exit 0
fi
exit 0
}
# **** Skim with Grep
RofiFind () {
echo "mynote.md"
}
# * Call Main Function
main "${@}"