Refactor
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
366a74575a
commit
eea5f442f9
1 changed files with 10 additions and 6 deletions
16
zet
16
zet
|
@ -43,7 +43,7 @@ delete_zet() {
|
|||
if [[ "$1" == "last" ]]; then
|
||||
file="$(find "$ZET_DIR" -type f -name "index.adoc" | sort | tail -1)"
|
||||
else
|
||||
file="${ZET_DIR}/${query}/index.adoc"
|
||||
file="$(get_filepath_for_zet "$query")"
|
||||
fi
|
||||
|
||||
if [[ -f "$file" ]]; then
|
||||
|
@ -82,7 +82,7 @@ edit_zet() {
|
|||
if [[ "$1" == "last" ]]; then
|
||||
file="$(find "$ZET_DIR" -type f -name "index.adoc" | sort | tail -1)"
|
||||
else
|
||||
file="${ZET_DIR}/${query}/index.adoc"
|
||||
file="$(get_filepath_for_zet "$query")"
|
||||
fi
|
||||
|
||||
if [[ -f "$file" ]]; then
|
||||
|
@ -122,6 +122,10 @@ generate_links() {
|
|||
done | sort
|
||||
}
|
||||
|
||||
get_filepath_for_zet() {
|
||||
echo "${ZET_DIR}/$1/index.adoc"
|
||||
}
|
||||
|
||||
get_zet_id_from_filename() {
|
||||
basename "$(dirname "$file")"
|
||||
}
|
||||
|
@ -144,7 +148,7 @@ main() {
|
|||
|
||||
new_zet() {
|
||||
id="$(date "+%Y%m%d%H%M%S")"
|
||||
filename="${ZET_DIR}/$id/index.adoc"
|
||||
filename="$(get_filepath_for_zet "$1")"
|
||||
mkdir -p "$(dirname "$filename")"
|
||||
|
||||
title="$*"
|
||||
|
@ -176,7 +180,7 @@ show_titles() {
|
|||
|
||||
show_zet() {
|
||||
id="$1"
|
||||
file="${ZET_DIR}/${id}/index.adoc"
|
||||
file="$(get_filepath_for_zet "$id")"
|
||||
|
||||
if [[ -f "$file" ]]; then
|
||||
cat "$file" && exit 0
|
||||
|
@ -187,9 +191,9 @@ show_zet() {
|
|||
}
|
||||
|
||||
update_zet_list() {
|
||||
find "$ZET_DIR" -type f -name 'index.adoc' | while read -r filename; do
|
||||
find "$ZET_DIR" -type f -name 'index.adoc' | while read -r file; do
|
||||
id="$(get_zet_id_from_filename "$file")"
|
||||
title=$(head -n 1 "$filename" | sed 's/^= //' | sed 's/^# //')
|
||||
title=$(head -n 1 "$file" | sed 's/^= //' | sed 's/^# //')
|
||||
|
||||
echo "$id $title"
|
||||
done | sort > "$ZET_TMP_FILE" &
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue