Til slutt for denne gang: Nåværende kode. Med kommentarer og ting jeg har lyst til å gjøre, og hvertfall én bug:
SPOILER ALERT! Vis spoiler
Kode
#!/bin/sh
# Input file with one project name per line.
# Output: Orgfile to be pasted into Spacemacs org-table, to prioritise projects
# Makes for a less visually distracting environment to think about these projects
# rhellcheck disable=SC2162 # read without -r will mangle backslashes - Here as example of shellcheck-ignore
# TODOs:
# Insert marker in inputfile when interrupting the script before going through the whole inputfile. Would this marker have to be ignored by the script too?
# Autocomplete words on tag-page
# Remove outputfile if it's empty - They're often created during testing, and are tedious to remove by hand, but I'd rather do that than lose data
# MAYBE:
# Keep character limit in mind(?) Not that important. Better be expressive than caring that much about the length. Display number of characters while typing?
# If answer to a different one is "skip", skip just that column
# Options? Well. What options would I want?
# Sorts tags alphabetically?
# Calculates scores? (Would be a double thing though. Here and in Spacemacs. If in this script too: Sort by score)
# WON'T:
# Separate output into functions. From http://mywiki.wooledge.org/BashWeaknesses on 29aug2019: "There's no way to tell a function the name of a variable where you want it to put its output" - So yes: *Can* be done, but probably, sadly, shouldn't.
# Highlights tags I've already written - #bash says ~impossible
clear
inputfile=$1
if [ "${inputfile}" = "" ]; then
inputfile=samplefile.txt
fi
current_line_num=1
# New file every time to avoid data loss. 29Aug2019_HH:MM:SS
timestamp_now=$(date +"%d%b%Y_%T")
outputfile="projectratings-${timestamp_now}.org"
touch "${outputfile}"
total_column=0
projects_already_done=0
# IFS= allows for spaces in the line
while IFS= read -r inputfile_line; do
projectname=${inputfile_line}
# Before progbar
num_of_input_lines=$(wc -l < "${inputfile}")
progfraction=$(printf '%s' "${current_line_num}/${num_of_input_lines}:" | tr -d ' ') # 6 extra spaces without the tr
rating_progress=$(echo "scale=3; ${current_line_num} / ${num_of_input_lines} * 100" | bc) && rating_progress=${rating_progress%.*} # Removes decimals
if [ "${projects_already_done}" -gt 0 ]; then
done_print=" - ${projects_already_done} done"
fi
print_before_progbar="${progfraction} ${rating_progress}%${done_print} " # Done here because num of chars determines progbar length
# Progbar
columns_in_terminal=$(tput cols) && progbar_blocks=$((columns_in_terminal - ${#print_before_progbar} - 2)) # The 2 []-brackets
progbar_completes_num=$((rating_progress * progbar_blocks/100)) && progbar_remains_num=$((progbar_blocks - progbar_completes_num))
i=0; while [ "${i}" -lt "${progbar_completes_num}" ]; do progbar_completes="${progbar_completes}#"; i=$((i + 1)); done # 1st symbol
i=0; while [ "${i}" -lt "${progbar_remains_num}" ]; do progbar_remains="${progbar_remains}."; i=$((i + 1)); done # 2nd symbol
progbar="[${progbar_completes}${progbar_remains}]" && progbar_completes="" && progbar_remains=""
# Header
header="${print_before_progbar}${progbar}"
# Project name
printf '%s\n' "${header}" "" "" "" "" "${inputfile_line}" # "1/10: 10%". Bumping down project name to make the transition to the next project more noticable
# Enter project name, or hit enter to keep current name
printf '%s' "1/9 Name? " && read -r new_name </dev/tty
clear && printf '%s\n' "${header}" "" ""
if [ "${new_name}" != "" ]; then
projectname=${new_name}
fi
# Done and skip
if [ "${new_name}" = "done" ]; then
projects_already_done=$((projects_already_done + 1))
elif [ "${new_name}" = "skip" ]; then
printf '%s\n' "${inputfile_line}" >> "${inputfile}"
else
# Description - Prints original input in case part of description is there
printf '%s\n' "(${inputfile_line})"
printf '%s\n' "${projectname}" && printf '%s' "2/9 Description? " && read -r description </dev/tty
# Tags - tag-script is not clear-ed, and shows what tags are already in use in the org-file
clear && printf '%s\n' "${header}" "" && tag && printf '%s\n' "---" "${projectname}" "${description}" && printf '%s' "3/9 Tags? " && read -r tags </dev/tty
# Int columns
int_column () {
clear && printf '%s\n' "${header}" "" "${projectname}" && printf '%s' "$1" && read -r "$2" </dev/tty && printf '\n'
}
progress="" && utility="" && fun="" && desire="" && size="" && difficulty="" # Fixes "References but not assigned" SC2154
int_column "4/9 Progress? " progress
int_column "5/9 Utility? " utility
int_column "6/9 Fun? " fun
int_column "7/9 Desire? " desire
int_column "8/9 Size? " size
int_column "9/9 Difficulty? " difficulty
printf '%s\n' "| ${total_column} | ${projectname} | ${description} | ${tags} | ${progress} | ${utility} | ${fun} | ${desire} | ${size} | ${difficulty} |" >> "${outputfile}"
fi
clear && current_line_num=$((current_line_num + 1))
done < "${inputfile}"
# Goodbyes
tput setaf 2 # Green
printf '%s\n' "All your base"
tput sgr0
sleep 0.3
clear
if [ "${header}" != "" ]; then # Empty inputfile? Don't print what would be an empty header
printf '%s\n' "${header}" # Showing user what they've just accomplished
fi
«Fy faen du oppfatter oss visst som barnslige as» - Tenk det da. Jeg skriver noe til en stor mengde folk, som jeg stort sett ikke har møtt, og det treffer ikke akkurat deg helt perfekt.