t script style
This commit is contained in:
parent
ccca6a92f9
commit
59f8ab46ea
@ -10,6 +10,9 @@ readonly EXIT_SUCCESS=0
|
|||||||
readonly NOTES_DIR_BASE="${HOME}/.t"
|
readonly NOTES_DIR_BASE="${HOME}/.t"
|
||||||
readonly NOTES_DIR="${NOTES_DIR_BASE}/${NS:-default}"
|
readonly NOTES_DIR="${NOTES_DIR_BASE}/${NS:-default}"
|
||||||
|
|
||||||
|
TAB="$(printf '\t')"
|
||||||
|
readonly TAB
|
||||||
|
|
||||||
|
|
||||||
cmd_help() {
|
cmd_help() {
|
||||||
echo "USAGE
|
echo "USAGE
|
||||||
@ -49,7 +52,11 @@ show_notes_with_indexes() {
|
|||||||
for note in $(find "${NOTES_DIR}" -maxdepth 1 -type f | sort -n)
|
for note in $(find "${NOTES_DIR}" -maxdepth 1 -type f | sort -n)
|
||||||
do
|
do
|
||||||
note_lines="$(wc -l < "${note}")"
|
note_lines="$(wc -l < "${note}")"
|
||||||
printf "[%d] %s (%s)\n" "${index}" "$(basename "${note}")" "${note_lines}"
|
if [ "${note_lines}" -gt 70 ]; then
|
||||||
|
note_lines="..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "[%d]\t%s\t(%s)\n" "${index}" "$(basename "${note}")" "${note_lines}"
|
||||||
index="$((index+1))"
|
index="$((index+1))"
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -57,7 +64,7 @@ show_notes_with_indexes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_remove_first_and_last_element() {
|
_remove_first_and_last_element() {
|
||||||
cut -d" " -f2- | rev | cut -d" " -f2- | rev
|
cut -d"${TAB}" -f2
|
||||||
}
|
}
|
||||||
|
|
||||||
find_note_name_by_index() {
|
find_note_name_by_index() {
|
||||||
@ -116,12 +123,22 @@ cmd_cat_note() {
|
|||||||
exit "$EXIT_SUCCESS"
|
exit "$EXIT_SUCCESS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prettify() {
|
||||||
|
column -t -s "${TAB}"
|
||||||
|
}
|
||||||
|
|
||||||
cmd_show_namespaces() {
|
cmd_show_namespaces() {
|
||||||
for ns in $(find "${NOTES_DIR_BASE}/" -mindepth 1 -maxdepth 1 -type d | sort -n)
|
(
|
||||||
do
|
for ns in $(find "${NOTES_DIR_BASE}/" -mindepth 1 -maxdepth 1 -type d | sort -n)
|
||||||
namespace_notes_count="$(find "${ns}" -type f | wc -l)"
|
do
|
||||||
printf "%s (%s)\n" "$(basename "${ns}")" "${namespace_notes_count}"
|
namespace_notes_count="$(find "${ns}" -type f | wc -l)"
|
||||||
done
|
printf "%s\t(%s)\n" "$(basename "${ns}")" "${namespace_notes_count}"
|
||||||
|
done
|
||||||
|
) | prettify
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_show_notes() {
|
||||||
|
show_notes_with_indexes | prettify
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_empty_namespaces() {
|
remove_empty_namespaces() {
|
||||||
@ -136,19 +153,19 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
if [ -z "${1+x}" ]; then
|
if [ -z "${1+x}" ]; then
|
||||||
show_notes_with_indexes
|
cmd_show_notes
|
||||||
exit "$EXIT_SUCCESS"
|
exit "$EXIT_SUCCESS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
show) shift; show_notes_with_indexes ;;
|
show) shift; cmd_show_notes ;;
|
||||||
ns|namespaces) shift; cmd_show_namespaces ;;
|
ns|namespaces) shift; cmd_show_namespaces ;;
|
||||||
add|a) shift; cmd_add_note "$@" ;;
|
add|a) shift; cmd_add_note "$@" ;;
|
||||||
delete|d) shift; cmd_delete_note "$@" ;;
|
delete|d) shift; cmd_delete_note "$@" ;;
|
||||||
e|edit) shift; cmd_edit_note "$@" ;;
|
e|edit) shift; cmd_edit_note "$@" ;;
|
||||||
--help) shift; cmd_help ;;
|
--help) shift; cmd_help ;;
|
||||||
|
|
||||||
*) cmd_cat_note "$@" ;;
|
*) cmd_cat_note "$@" ;;
|
||||||
esac
|
esac
|
||||||
exit "$EXIT_SUCCESS"
|
exit "$EXIT_SUCCESS"
|
||||||
Loading…
x
Reference in New Issue
Block a user