aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorziggys <ziggys@autistici.org>2019-11-11 14:58:55 -0300
committerziggys <ziggys@autistici.org>2019-11-11 14:58:55 -0300
commit033ecd591a6de8c46ea453031fdf0c03881dc325 (patch)
tree08ad4e353f5d996d60e41218c4a99ac6eec40ccc
parent3bde0294a2ae14106c6ab88f2e2f34118b832b07 (diff)
downloadgsocial-cli-033ecd591a6de8c46ea453031fdf0c03881dc325.tar
gsocial-cli-033ecd591a6de8c46ea453031fdf0c03881dc325.zip
prettify output
-rwxr-xr-xgsocial-cli.sh74
1 files changed, 12 insertions, 62 deletions
diff --git a/gsocial-cli.sh b/gsocial-cli.sh
index 66bb119..451158e 100755
--- a/gsocial-cli.sh
+++ b/gsocial-cli.sh
@@ -243,17 +243,7 @@ tget () {
"${good_c}" "${RETR}" "${good_c}" "${TGET}"
TIMELINEF="$(mktemp -p "${TMPDIR}")"
- OUTPUT0="$(mktemp -p "${TMPDIR}")"
- OUTPUT1="$(mktemp -p "${TMPDIR}")"
- OUTPUT2="$(mktemp -p "${TMPDIR}")"
- OUTPUT3="$(mktemp -p "${TMPDIR}")"
OUTPUT4="$(mktemp -p "${TMPDIR}")"
- SIDSF="$(mktemp -p "${TMPDIR}")"
- SNAMESF="$(mktemp -p "${TMPDIR}")"
- UNAMESF="$(mktemp -p "${TMPDIR}")"
- TEXTSF="$(mktemp -p "${TMPDIR}")"
- SOURCESF="$(mktemp -p "${TMPDIR}")"
- CREATEDSF="$(mktemp -p "${TMPDIR}")"
OIFS="$IFS"
IFS="$(printf '\n')"
@@ -300,12 +290,6 @@ tget () {
> "${TIMELINEF}"
SID="$(jq -r '.[] | .id' "${TIMELINEF}")"
- SNAME="$(jq -r '.[] | .user.screen_name' "${TIMELINEF}")"
-
- UNAME="$(jq -r '.[] | .user.name' "${TIMELINEF}")"
- TEXT="$(jq -r '.[] | .text' "${TIMELINEF}")"
- SSOURCE="$(jq -r '.[] | .source' "${TIMELINEF}")"
- CREATED="$(jq -r '.[] | .created_at' "${TIMELINEF}")"
test -z "${SID}" \
&& printf "\\e%swarning:\\e%s command returned an empty output\\e[0m\\n" \
@@ -313,74 +297,40 @@ tget () {
&& printf "exiting now..." \
&& exit 0
- # many shells do not handle arrays, let's make lists
- echo "${SID}" > "${SIDSF}"
- echo "${SNAME}" > "${SNAMESF}"
- echo "${UNAME}" > "${UNAMESF}"
- echo "${TEXT}" > "${TEXTSF}"
- echo "${SSOURCE}" > "${SOURCESF}"
- echo "${CREATED}" > "${CREATEDSF}"
- sed -i 's/&quot;/"/g' "${TEXTSF}"
-
- # let's use awk to concatenate lists
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${SIDSF}" "${SNAMESF}" > "${OUTPUT0}"
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${OUTPUT0}" "${UNAMESF}" > "${OUTPUT1}"
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${OUTPUT1}" "${TEXTSF}" > "${OUTPUT2}"
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${OUTPUT2}" "${SOURCESF}" > "${OUTPUT3}"
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${OUTPUT3}" "${CREATEDSF}" > "${OUTPUT4}"
-
- # print concatenated file
+ jq -r '.[] | .user.name + ":;:" + .user.screen_name + ":;:" + (.id|tostring) + ":;:" + (.text|split("\n\n")|join(" ")) + ":;:" + (.created_at|tostring) + ":;:" + .source' "${TIMELINEF}" > "${OUTPUT4}"
+
awk -v user="${USER}" '
BEGIN{FS=":;:"; OFS="\n"}
{
if ($2==user)
printf \
- "\033['"$myself_c"'" $3 \
+ "\033['"$myself_c"'" $1 \
"\033['"$uname_c"'" " @" $2 \
- "\033['"$myself_c"'" " [" NR " - id " $1 "]" OFS \
+ "\033['"$myself_c"'" " [" NR " - id " $3 "]" OFS \
"\033[1;30m" $4 OFS \
"\033[1;30m" " - " \
- "\033['"$text_c"'" $6 \
+ "\033['"$text_c"'" $5 \
"\033[1;30m" " from " \
- "\033['"$text_c"'" $5 OFS \
+ "\033['"$text_c"'" $6 OFS OFS \
"\033[0m"
else
printf \
- "\033['"$sname_c"'" $3 \
+ "\033['"$sname_c"'" $1 \
"\033['"$uname_c"'" " @" $2 \
- "\033['"$sid_c"'" " [" NR " - id " $1 "]" OFS \
+ "\033['"$sid_c"'" " [" NR " - id " $3 "]" OFS \
"\033['"$text_c"'" $4 OFS \
"\033['"$text_c"'" " - " \
- "\033['"$meta_c"'" $6 \
+ "\033['"$meta_c"'" $5 \
"\033['"$text_c"'" " from " \
- "\033['"$meta_c"'" $5 OFS OFS \
+ "\033['"$meta_c"'" $6 OFS OFS \
"\033[0m" }' \
"${OUTPUT4}" | more
-
+
history_keep
cat "$OUTPUT4" >> "${HISTORY}" && chmod 600 "${HISTORY}"
IFS="${OIFS}"
+
}
# repeat, favorite, destroy