~reykjalin/public-inbox

Improve POSIX compliance in tday-sh v1 APPLIED

Kristófer Reykjalín Þorláksson: 5
 use posix compliant conditional operators
 Set IFS in a POSIX compliant way
 Remove non-POSIX compliant pipefail
 properly quote variable expansions
 Replace ls pipeline with a find command

 5 files changed, 14 insertions(+), 13 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~reykjalin/public-inbox/patches/21460/mbox | git am -3
Learn more about email & git

[PATCH 1/5] use posix compliant conditional operators Export this patch

From: Kristófer R <kristofer.thorlaksson@automattic.com>

---
 tday | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tday b/tday
index 9f4e749..853a428 100755
--- a/tday
+++ b/tday
@@ -8,8 +8,8 @@ storage=~/.local/tday
date=$(date '+%Y-%m-%d')
curr_file=${storage}/${date}.tday

[[ -d ${storage} ]] || mkdir -p ${storage}
[[ -f ${curr_file} ]] || touch ${curr_file}
[ -d ${storage} ] || mkdir -p ${storage}
[ -f ${curr_file} ] || touch ${curr_file}

cmd=${1:-}

-- 
2.30.2

[PATCH 2/5] Set IFS in a POSIX compliant way Export this patch

From: Kristófer R <kristofer.thorlaksson@automattic.com>

---
 tday | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tday b/tday
index 853a428..a4926c4 100755
--- a/tday
+++ b/tday
@@ -1,7 +1,8 @@
#!/bin/sh

set -euo pipefail
IFS=$'\n\t'
IFS="
	" # Set IFS to newlines and tabs (string contains a newline, followed by a tab)

storage=~/.local/tday

-- 
2.30.2

[PATCH 3/5] Remove non-POSIX compliant pipefail Export this patch

From: Kristófer R <kristofer.thorlaksson@automattic.com>

---
 tday | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tday b/tday
index a4926c4..c303bb4 100755
--- a/tday
+++ b/tday
@@ -1,6 +1,6 @@
#!/bin/sh

set -euo pipefail
set -eu
IFS="
	" # Set IFS to newlines and tabs (string contains a newline, followed by a tab)

-- 
2.30.2

[PATCH 4/5] properly quote variable expansions Export this patch

From: Kristófer R <kristofer.thorlaksson@automattic.com>

---
 tday | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tday b/tday
index c303bb4..698581e 100755
--- a/tday
+++ b/tday
@@ -6,26 +6,26 @@ IFS="

storage=~/.local/tday

date=$(date '+%Y-%m-%d')
curr_file=${storage}/${date}.tday
date=$(date "+%Y-%m-%d")
curr_file="${storage}/${date}.tday"

[ -d ${storage} ] || mkdir -p ${storage}
[ -f ${curr_file} ] || touch ${curr_file}
[ -d "${storage}" ] || mkdir -p "${storage}"
[ -f "${curr_file}" ] || touch "${curr_file}"

cmd=${1:-}

case ${cmd} in
	edit)
		${EDITOR:-nano} ${curr_file}
		${EDITOR:-nano} "${curr_file}"
		;;
	incomplete)
		cat $(ls -d ${storage}/*.tday) | sort -r | grep '^o'
		cat "${storage}"/*.tday | sort -r | grep "^o"
		;;
	list)
		ls ${storage} | grep '.tday$' | sort -r
		ls "${storage}" | grep '.tday$' | sort -r
		;;
	*)
		cat ${curr_file}
		cat "${curr_file}"
		;;
esac

-- 
2.30.2

[PATCH 5/5] Replace ls pipeline with a find command Export this patch

From: Kristófer R <kristofer.thorlaksson@automattic.com>

---
 tday | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tday b/tday
index 698581e..cd6b809 100755
--- a/tday
+++ b/tday
@@ -22,7 +22,7 @@ case ${cmd} in
		cat "${storage}"/*.tday | sort -r | grep "^o"
		;;
	list)
		ls "${storage}" | grep '.tday$' | sort -r
		find "${storage}" -name "*.tday" -exec basename {} ";" | sort -r
		;;
	*)
		cat "${curr_file}"
-- 
2.30.2