The time now is Tue 09 Mar 2021, 06:09
All times are UTC - 4 |
Author |
Message |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Wed 05 Dec 2018, 04:44 Post subject:
|
|
Sorry to bother you!
I'm sure this insignificant script displaying a month
-- colored with some colors in the 90's register of ANSI codes
-- fading according to in-focus and out-of-focus
-- with the single numbers of the month padded
-- with a little motto at the bottom (hopefully inspiring!)
-- using < rxvt > and < less > to produce a pseudo-GUI
-- multilingual (plus you could add your own locale)
-- with a suggested entry for a pekwm or ae menu
is off-topic and of no interest to anyone!
BFN
Description |
|
Filesize |
62.99 KB |
Viewed |
368 Time(s) |

|
Description |
|

Download |
Filename |
hic-et-nunc4.sh.zip |
Filesize |
2.25 KB |
Downloaded |
159 Time(s) |
Description |
French version (sorry to impose). But if LANG variable NOT set to fr, will display in English. |
Filesize |
65.43 KB |
Viewed |
439 Time(s) |

|
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Last edited by musher0 on Thu 06 Dec 2018, 19:05; edited 1 time in total
|
Back to top
|
|
 |
puppy_apprentice

Joined: 07 Feb 2012 Posts: 300
|
Posted: Thu 06 Dec 2018, 16:59 Post subject:
|
|
MochiMoppel wrote: |
With little extra code it is possible to pull dates from a database and mark them in the calendar. These dates can be public holidays, birthdays, dentist appointments or whatever. |
I'm working on something similar with coloring done it this way (without curses it will be hard to make windows and menus but i'm thinking to use 'select' or 'tput' command):
Code: | cal | grep -w --color=always "$(seq 1 2 31)" | sed 's/31m/32m/g' |
or
Code: | a=$(cal | grep -w --color=always "$(seq 1 2 31)"); echo "${a//31m/34m}" |
Code: | cal | grep -w -B 6 -A 6 --color=always 10 | sed 's/31m/32m/g' | grep -w -B 6 -A 6 --color=always 20 |
where '31' is standard color from grep command.
|
Back to top
|
|
 |
Burunduk
Joined: 21 Aug 2011 Posts: 80
|
Posted: Sun 16 Dec 2018, 17:35 Post subject:
|
|
MochiMoppel wrote: | Are you sure? Does not work when the year is 2018 and day is the 18th
|
Thank you for fixing that nasty bug
I like your idea of using "pipe-separated values" as a part of a regexp. It is also possible to apply this technique to the entire year view:
Code: | #!/bin/bash
# Highlights dates from two sets in the cal command output
# using distinct styles (in the month and year view).
# Requires GNU sed. Busybox sed doesn't understand multibytes chars
# (it seems to be the compile option).
# It also doesn't support s/.../.../Ng options combo
# but this can be worked around:
#
# mark_days="$mark_days
# $addr,+6 { s/./!/22; s/./!/44; s/...?!?/%$i-&/g
# :a$i; s/(!.*%)$i/\1$((i+1))/; ta$i; s/!/ /
# :b$i; s/(!.*%)$((i+1))/\1$((i+2))/; tb$i; s/!/ /
# }"
#
# Usage: ./this_script [ [month] year ]
# No error checking. This is just a demo.
# cal and busybox cal insert empty lines in different places
CALCMD="busybox cal" addr=4 inc=8
#CALCMD="cal -h" addr=3 inc=9
# Highlight:
# 1st set of days
daysA="1-1|1-7|12-25|12-26|12-31"
# 2nd set of days
daysB="1-2|12-31"
# columns
daysC="1|6|7"
# Styles:
onA=$'\x1b[1;37;42m' # for the 1st set
offA=$'\x1b[0m' # turn the style off
onB=$'\x1b[1;35m' # for the 2nd set
offB="$offA"
onAB=$'\x1b[1;37;45m' # for the intersection of the two sets
offAB="$offA"
onC=$'\x1b[1;31m' # for columns (if no other style applies)
offC="$offA"
# Settings for the month and year view
case $# in
0) months=`date +%m`
addr=2
;;
1) months='1 4 7 10'
;;
2) months=${1%%[^0-9]*}
addr=2
;;
esac
# Generate repetitive parts of the sed script:
# add month labels before every 3rd char (skipping spaces between months)
mark_days=
for i in $months; do
mark_days="$mark_days
$addr,+6 { s/./!/22; s/./!/44; s/...?!?/%$i-&/g; s/!/ /g
s/%$i/%$((i+1))/8g; s/%$((i+1))/%$((i+2))/8g
} "
addr=$((addr+inc))
done
# add style labels to the specified columns
mark_columns=
for i in ${daysC//|/ }; do
mark_columns="$mark_columns
$(printf "s/%%/C%%/%i;" $i $((i+7)) $((i+14)) )"
done
# Apply styles
$CALCMD "$@" | sed -r "
$mark_days
$mark_columns
# mark days from the sets
s/- /-/g
s/%($daysA)( |$)/A&/g
s/%($daysB)( |$)/B&/g
s/-(.( |$))/- \1/g
# replace marks with the actual style markup
s/C?AB%..?-(..)/$onAB\1$offAB/g
s/C?A%..?-(..)/$onA\1$offA/g
s/C?B%..?-(..)/$onB\1$offB/g
s/C%..?-([^ ].| [^ ])/$onC\1$offC/g # or /C%..?-(..)/
s/C?%..?-(..)/\1/g # remove unused marks
"
|
===
musher0 wrote: | I just did a < busybox --list > on my xenialPup, and it does not have a
< busybox awk >. |
Probably the easiest way to test busybox awk is by downloading a statically compiled binary from the official site.
https://busybox.net/downloads/binaries
Code: | root# busybox awk
awk: applet not found
root# chmod 755 busybox-i686
root# ./busybox-i686 awk
BusyBox v1.28.1 (2018-02-15 14:34:02 CET) multi-call binary.
Usage: awk [OPTIONS] [AWK_PROGRAM] [FILE]...
-v VAR=VAL Set variable
-F SEP Use SEP as field separator
-f FILE Read program from FILE
-e AWK_PROGRAM |
Description |
colored cal command |
Filesize |
12.61 KB |
Viewed |
335 Time(s) |

|
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 2084 Location: Japan
|
Posted: Tue 25 Dec 2018, 01:54 Post subject:
|
|
Burunduk wrote: | It is also possible to apply this technique to the entire year view | Well done!
I never thought that anyone would try to do this
Quote: | Busybox sed doesn't understand multibytes chars | Well, it understands multibyte chars when inserted directly or via variable, not when the chars are represented by escape codes. But I don't see such chars in your code. I only see that busybox sed doesn't work. Can you point me to an expression where busybox sed fails?
These binaries seem to be compiled with CONFIG_LOCALE_SUPPORT not enabled. They are English only. It would be great if you or anyone else knows where to download a recent busybox with support for locales.
|
Back to top
|
|
 |
Burunduk
Joined: 21 Aug 2011 Posts: 80
|
Posted: Sun 30 Dec 2018, 16:58 Post subject:
|
|
OK, this is a bit late respond but anyway...
MochiMoppel wrote: | Well, it understands multibyte chars when inserted directly or via variable, not when the chars are represented by escape codes. But I don't see such chars in your code. I only see that busybox sed doesn't work. Can you point me to an expression where busybox sed fails? |
There are several problems with busybox here.
Multibyte characters may appear in the cal command output and what busybox sees is a bytestring. This means that I can't use dots in the regexps.
Code: | # echo "żółw" | busybox sed 's/./1/g' | wc -c
8
# echo "żółw" | sed 's/./1/g' | wc -c
5 |
Now, a command like s/a/b/5g fails because busybox ignores the number and replaces all the matches.
And the old versions of busybox have a bug: s/a/b/5; results in an unrecognized option error while s/a/b/5 ; (with a space before ; ) works.
And addresses like 1,+2 aren't supported by the old busybox versions.
I've rewritten the script so it should work with busybox now.
Code: | #!/bin/busybox sh
# Highlights dates from two sets in the cal command output
# using distinct styles (in the month and year view).
# This version outputs an HTML document.
# Should work with busybox utilities.
# Usage: ./this_script [ [month] year ] >cal.html
# No error checking. This is just a demo.
# cal and busybox cal insert empty lines in different places
CALCMD="busybox cal" addr=4 inc=8
#CALCMD="/usr/bin/cal -h" addr=3 inc=9
# Highlight:
# 1st set of days
daysA="1-1|1-7|12-25|12-26|12-31"
# 2nd set of days
daysB="1-2|12-31"
# columns
daysC="1|6|7"
# Styles:
# for terminal ---
#before=
#after=
#
#onA=$'\x1b[1;37;42m' # for the 1st set
#offA=$'\x1b[0m' # turn the style off
#
#onB=$'\x1b[1;35m' # for the 2nd set
#offB="$offA"
#
#onAB=$'\x1b[1;37;45m' # for the intersection of the two sets
#offAB="$offA"
#
#onC=$'\x1b[1;31m' # for columns (if no other style applies)
#offC="$offA"
# ---
# for html ---
before="
<!DOCTYPE html>
<html><head>
<title>Kalendarz</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<style>
.a { color: olive }
.b { color: snow; background-color: springgreen }
.ab { color: mintcream; background-color: orchid }
.c { color: tomato }
</style>
</head><body>
<pre>
"
after="
</pre>
</body></html>
"
onA='<span class=\"a\">'
offA='<\/span>'
onB='<span class=\"b\">'
offB="$offA"
onAB='<span class=\"ab\">'
offAB="$offA"
onC='<span class=\"c\">'
offC="$offA"
# ---
# Settings for the month and year view
case $# in
0) months=`date +%m`
addr=2
;;
1) months='1 4 7 10'
;;
2) months=${1%%[^0-9]*}
addr=2
;;
esac
# Generate repetitive parts of the sed script:
# add month labels before every 3rd char (skipping spaces between months)
mark_days=
for i in $months; do
mark_days="$mark_days
$addr s/[^ ]+/%-&/g
$((addr+1)),$((addr+6)) { s/./!/22 ; s/./!/44 ; s/...?!?/%$i-&/g
:a$i; s/(!.*%)$i/\1$((i+1))/; ta$i; s/!/ /
:b$i; s/(!.*%)$((i+1))/\1$((i+2))/; tb$i; s/!/ /
# s commands here are repeated until they fail
}"
addr=$((addr+inc))
done
# add style labels to the specified columns
mark_columns=
for i in ${daysC//|/ }; do
mark_columns="$mark_columns
$(printf "s/%%/C%%/%i ; " $i $((i+7)) $((i+14)) )"
done
# Apply styles
echo -n "$before"
$CALCMD "$@" | sed -r "
$mark_days
$mark_columns
# mark days from the sets
s/- /-/g
s/%($daysA)( |$)/A&/g
s/%($daysB)( |$)/B&/g
s/-(.( |$))/- \1/g
# replace marks with the actual style markup
s/C?AB%..?-(..)/$onAB\1$offAB/g
s/C?A%..?-(..)/$onA\1$offA/g
s/C?B%..?-(..)/$onB\1$offB/g
s/C%[^-]*-( ?[^ ]+)( |$)/$onC\1$offC\2/g
s/C?%[^-]*-//g # remove unused marks
"
echo -n "$after"
|
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Sun 30 Dec 2018, 19:20 Post subject:
|
|
Hello all.
Please find attached a variant of my "completely useless" DB-type
approach above: Code: | #!/bin/bash
# /root/my-applications/bin/mois_zeros+espaces.sh
# Sketch by musher0, 26 Nov. 2018. GPL3. # Rev. 30 déc. 2018.
#
# Requires awk, replaceit, tr, and paste.
#
# Syntax should be < mois_zeros_espaces.sh month year >, but there
# is a safeguard: it defaults to current month and year if the
# script finds no positional parameters.
#
# Please read NOTE at bottom.
####
[ "$1" ] && A=$1 || A="`date '+%m'`" # mois
[ "$2" ] && B=$2 || B="`date '+%Y'`" # année
TmP=/root/my-documents/tmp
MoiS="$TmP/mois.txt"
RPLCT="replaceit --input=$MoiS"
EnTete="`cal $A $B | grep -vE [[:digit:]] | tr " " "\t"`"
echo " " > $MoiS # For better appearance in the end.
cal $A $B | grep --color=always -vE [[:alpha:]] | tr " " ";" >> $MoiS
echo $MOIS
num="";for num in {1..9};do
$RPLCT ";;$num" ";0$num";$RPLCT ";$num;" "0$num;"
done
i=1;for i in {1..7};do
$RPLCT ";;;" " o "
i="$[$i+i]"
done
# Maintenant on a un mois avec des dates de même longueur,
# tous séparés par un espace. /
# Now we have a month with dates of same length, all
# separated by a space.
cat $MoiS | tr ";" " " > $TmP/mois.txt2
for i in {1..7}; do # séparation en colonnes (simili-BdD)
awk '{ print $'$i' }' $TmP/mois.txt2 | tr "o" "-" > $TmP/jours$i.txt
done
for j in 1 7;do
> $TmP/jours$j.txt2
while read line;do
echo -e "\e[32m$line\e[0m" >> $TmP/jours$j.txt2
done < $TmP/jours$j.txt
mv $TmP/jours$j.txt2 $TmP/jours$j.txt
done
# Affichage
clear
echo; echo -e "\t\t\t\e[1;33m`cal $A $B | head -1`\e[0m"
paste /root/my-applications/bin/taquets.txt $TmP/jours*.txt
echo -e "\n\t\e[1;33m$EnTete\e[0m"
# Nettoyage
rm -f $TmP/mois.tx*
read
rm -f $TmP/jours*
exit
## NOTE ##
# To run in its own window, in your Puppy's locale:
# urxvt +sb -bg "#352e20" -g 67x13 -e mois_zeros+espaces.sh
# To run in its own window, in English:
# LANG=en_CA;urxvt +sb -bg "#352e20" -g 67x13 -e mois_zeros+espaces.sh
########## |
 |
Description |
(Same as above, zipped. Pls remember to make executable before running.)
|

Download |
Filename |
mois_zeros+espaces.sh.zip |
Filesize |
1.17 KB |
Downloaded |
153 Time(s) |
Description |
|
Filesize |
69.29 KB |
Viewed |
207 Time(s) |

|
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 2084 Location: Japan
|
Posted: Mon 31 Dec 2018, 02:10 Post subject:
|
|
Burunduk wrote: | This means that I can't use dots in the regexps.
Code: | # echo "żółw" | busybox sed 's/./1/g' | wc -c
8
# echo "żółw" | sed 's/./1/g' | wc -c
5 |
| Are you by any chance using the busybox version you recommended for download? As you've already noticed and I said before: this version is English only. Any of the Puppy busybox versions should produce the correct result of 5.
Quote: | Now, a command like s/a/b/5g fails because busybox ignores the number and replaces all the matches. | It doesn't "fail", it only tries to make sense of an ambiguous command. What do you expect it to produce when you instruct it to a) replace only the 5th match? and b) replace all matches ?
When you use two contradicting flags, newer busyboxes ignore the first flag and honor only the last:
Code: | # echo a..a...a...a..a | busybox sed s/a/X/3g
X..X...X...X..X |
If you change the order of the flags in the example, busybox will ignore 'g':
Code: | # echo a..a...a...a..a | busybox sed s/a/X/g3
a..a...X...a..a | This is also the result I get from my older busybox 1.21.0, regardless of the g3 order.
GNU sed output is still different. Matches from the 3rd to the last are replaced, matches before the 3rd are ignored.
Bottomline: avoid ambiguous commands.
|
Back to top
|
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|