A bit of Bash and Terminal Help

Not so much assistance but help to understand where I went wrong.
I want the weather etc at the top of my Garuda Fish Terminal, like this :-1:


So I followed the instructions and added this to the top of my .bashrc file.

#!/bin/bash

# NAME: now
# PATH: $HOME/bin
# DESC: Display current weather, calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: May 24, 2019.

# UPDT: 2019-05-24 If Weather unavailable nicely formatted error message.

# NOTE: To display all available toilet fonts use this one-liner:
#       for i in ${TOILET_FONT_PATH:=/usr/share/figlet}/*.{t,f}lf; do j=${i##*/}; toilet -d "${i%/*}" -f "$j" "${j%.*}"; done

# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for   "   "   "   "    61 "   "   "   "

# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Edmonton?0 --silent --max-time 3 > /tmp/now-weather
# Timeout #. Increase for slow connection---^

readarray aWeather < /tmp/now-weather
rm -f /tmp/now-weather

# Was valid weather report found or an error message?
if [[ "${aWeather[0]}" == "Weather report:"* ]] ; then
    WeatherSuccess=true
    echo "${aWeather[@]}"
else
    WeatherSuccess=false
    echo "+============================+"
    echo "| Weather unavailable now!!! |"
    echo "| Check reason with command: |"
    echo "|                            |"
    echo "| curl wttr.in/Edmonton?0    |" # Replace Edmonton with your city
    echo "|   --silent --max-time 3    |"
    echo "+============================+"
    echo " "
fi
echo " "                # Pad blank lines for calendar & time to fit

#--------- DATE -------------------------------------------------------------

# calendar current month with today highlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
#        36=cyan, 37=white

tput sc                 # Save cursor position.
# Move up 9 lines
i=0
while [ $((++i)) -lt 10 ]; do tput cuu1; done

if [[ "$WeatherSuccess" == true ]] ; then
    # Depending on length of your city name and country name you will:
    #   1. Comment out next three lines of code. Uncomment fourth code line.
    #   2. Change subtraction value and set number of print spaces to match
    #      subtraction value. Then place comment on fourth code line.
    Column=$((DateColumn - 10))
    tput cuf $Column        # Move x column number
    # Blank out ", country" with x spaces
    printf "          "
else
    tput cuf $DateColumn    # Position to column 27 for date display
fi

# -h needed to turn off formating: https://askubuntu.com/questions/1013954/bash-substring-stringoffsetlength-error/1013960#1013960
cal > /tmp/terminal1
# -h not supported in Ubuntu 18.04. Use second answer: https://askubuntu.com/a/1028566/307523
tr -cd '\11\12\15\40\60-\136\140-\176' < /tmp/terminal1  > /tmp/terminal

CalLineCnt=1
Today=$(date +"%e")

printf "\033[32m"   # color green -- see list above.

while IFS= read -r Cal; do
    printf "%s" "$Cal"
    if [[ $CalLineCnt -gt 2 ]] ; then
        # See if today is on current line & invert background
        tput cub 22
        for (( j=0 ; j <= 18 ; j += 3 )) ; do
            Test=${Cal:$j:2}            # Current day on calendar line
            if [[ "$Test" == "$Today" ]] ; then
                printf "\033[7m"        # Reverse: [ 7 m
                printf "%s" "$Today"
                printf "\033[0m"        # Normal: [ 0 m
                printf "\033[32m"       # color green -- see list above.
                tput cuf 1
            else
                tput cuf 3
            fi
        done
    fi

    tput cud1               # Down one line
    tput cuf $DateColumn    # Move 27 columns right
    CalLineCnt=$((++CalLineCnt))
done < /tmp/terminal

printf "\033[00m"           # color -- bright white (default)
echo ""

tput rc                     # Restore saved cursor position.

#-------- TIME --------------------------------------------------------------

tput sc                 # Save cursor position.
# Move up 8 lines
i=0
while [ $((++i)) -lt 9 ]; do tput cuu1; done
tput cuf $TimeColumn    # Move 49 columns right

# Do we have the toilet package?
if hash toilet 2>/dev/null; then
    echo " $(date +"%I:%M %P") " | \
        toilet -f future --filter border > /tmp/terminal
# Do we have the figlet package?
elif hash figlet 2>/dev/null; then
#    echo $(date +"%I:%M %P") | figlet > /tmp/terminal
    date +"%I:%M %P" | figlet > /tmp/terminal
# else use standard font
else
#    echo $(date +"%I:%M %P") > /tmp/terminal
    date +"%I:%M %P" > /tmp/terminal
fi

while IFS= read -r Time; do
    printf "\033[01;36m"    # color cyan
    printf "%s" "$Time"
    tput cud1               # Up one line
    tput cuf $TimeColumn    # Move 49 columns right
done < /tmp/terminal

tput rc                     # Restore saved cursor position.

exit 0

But then I couldn’t log on :upside_down_face:
What am I doing wrong?

System:
Kernel: 6.9.6-zen1-1-zen arch: x86_64 bits: 64 compiler: gcc v: 14.1.1
clocksource: tsc avail: hpet,acpi_pm
parameters: BOOT_IMAGE=/@/boot/vmlinuz-linux-zen
root=UUID=7b049ab1-cf8c-4eb1-809e-b21343f9b233 rw rootflags=subvol=@
quiet loglevel=3 ibt=off
Desktop: KDE Plasma v: 6.1.0 tk: Qt v: N/A wm: kwin_wayland dm: SDDM
Distro: Garuda base: Arch Linux
Machine:
Type: Desktop Mobo: MSI model: A68HM-E33 V2 (MS-7721) v: 9.0 serial: N/A
uuid: 00000000-0000-0000-0000-4ccc6a46edf4 UEFI: American Megatrends v: 8.5
date: 11/01/2018
CPU:
Info: model: AMD Athlon X4 860K socket: FM2 (P0) note: check bits: 64
type: MCP arch: Steamroller level: v2 built: 2014 process: GF 28nm
family: 0x15 (21) model-id: 0x30 (48) stepping: 1 microcode: 0x6003106
Topology: cpus: 1x cores: 4 smt: <unsupported> cache: L1: 256 KiB
desc: d-4x16 KiB; i-2x96 KiB L2: 4 MiB desc: 2x2 MiB
Speed (MHz): avg: 3700 min/max: 1700/3700 boost: enabled
base/boost: 3700/3700 scaling: driver: acpi-cpufreq governor: performance
volts: 1.3 V ext-clock: 100 MHz cores: 1: 3700 2: 3700 3: 3700 4: 3700
bogomips: 29543
Flags: avx ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
Vulnerabilities: <filter>
Graphics:
Device-1: AMD Baffin [Radeon RX 460/560D / Pro
450/455/460/555/555X/560/560X] vendor: PC Partner / Sapphire
driver: amdgpu v: kernel arch: GCN-4 code: Arctic Islands process: GF 14nm
built: 2016-20 pcie: gen: 3 speed: 8 GT/s lanes: 8 ports:
active: DP-1,HDMI-A-1 empty: DVI-D-1 bus-ID: 01:00.0 chip-ID: 1002:67ef
class-ID: 0300 temp: 43.0 C
Device-2: Logitech BRIO Ultra HD Webcam driver: snd-usb-audio,uvcvideo
type: USB rev: 2.1 speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 3-2:2
chip-ID: 046d:085e class-ID: 0102 serial: <filter>
Display: unspecified server: X.Org v: 24.1 with: Xwayland v: 24.1.0
compositor: kwin_wayland driver: X: loaded: amdgpu unloaded: modesetting
alternate: fbdev,vesa dri: radeonsi gpu: amdgpu display-ID: :1 screens: 1
Screen-1: 0 s-res: 3840x1080 s-dpi: 96 s-size: 1016x286mm (40.00x11.26")
s-diag: 1055mm (41.55")
Monitor-1: DP-1 pos: primary,left model: Dell S2721H serial: <filter>
built: 2020 res: 1920x1080 hz: 60 dpi: 82 gamma: 1.2
size: 598x336mm (23.54x13.23") diag: 686mm (27") ratio: 16:9 modes:
max: 1920x1080 min: 720x400
Monitor-2: HDMI-A-1 pos: right model: Dell S2721H serial: <filter>
built: 2022 res: 1920x1080 hz: 60 dpi: 82 gamma: 1.2
size: 598x336mm (23.54x13.23") diag: 686mm (27") ratio: 16:9 modes:
max: 1920x1080 min: 720x400
API: EGL v: 1.5 hw: drv: amd radeonsi platforms: device: 0 drv: radeonsi
device: 1 drv: swrast surfaceless: drv: radeonsi x11: drv: radeonsi
inactive: gbm,wayland
API: OpenGL v: 4.6 compat-v: 4.5 vendor: amd mesa v: 24.1.2-arch1.1
glx-v: 1.4 direct-render: yes renderer: AMD Radeon RX 460 Graphics
(radeonsi polaris11 LLVM 17.0.6 DRM 3.57 6.9.6-zen1-1-zen)
device-ID: 1002:67ef memory: 1.95 GiB unified: no
API: Vulkan v: 1.3.279 layers: 3 device: 0 type: discrete-gpu name: AMD
Radeon RX 460 Graphics (RADV POLARIS11) driver: mesa radv
v: 24.1.2-arch1.1 device-ID: 1002:67ef surfaces: xcb,xlib device: 1
type: cpu name: llvmpipe (LLVM 17.0.6 256 bits) driver: mesa llvmpipe
v: 24.1.2-arch1.1 (LLVM 17.0.6) device-ID: 10005:0000 surfaces: xcb,xlib
Audio:
Device-1: AMD FCH Azalia vendor: Micro-Star MSI driver: snd_hda_intel
v: kernel bus-ID: 00:14.2 chip-ID: 1022:780d class-ID: 0403
Device-2: AMD Baffin HDMI/DP Audio [Radeon RX 550 640SP / 560/560X]
vendor: PC Partner / Sapphire driver: snd_hda_intel v: kernel pcie: gen: 3
speed: 8 GT/s lanes: 8 bus-ID: 01:00.1 chip-ID: 1002:aae0 class-ID: 0403
Device-3: Logitech BRIO Ultra HD Webcam driver: snd-usb-audio,uvcvideo
type: USB rev: 2.1 speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 3-2:2
chip-ID: 046d:085e class-ID: 0102 serial: <filter>
API: ALSA v: k6.9.6-zen1-1-zen status: kernel-api tools: N/A
Server-1: PipeWire v: 1.0.7 status: n/a (root, process) with:
1: pipewire-pulse status: active 2: wireplumber status: active
3: pipewire-alsa type: plugin 4: pw-jack type: plugin
tools: pactl,pw-cat,pw-cli,wpctl
Network:
Device-1: Realtek RTL8111/8168/8211/8411 PCI Express Gigabit Ethernet
vendor: Micro-Star MSI driver: r8169 v: kernel pcie: gen: 1 speed: 2.5 GT/s
lanes: 1 port: d000 bus-ID: 02:00.0 chip-ID: 10ec:8168 class-ID: 0200
IF: enp2s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
IF-ID-1: wgpia0 state: unknown speed: N/A duplex: N/A mac: N/A
Info: services: NetworkManager,systemd-timesyncd
Drives:
Local Storage: total: 1.35 TiB used: 439.19 GiB (31.9%)
ID-1: /dev/sda maj-min: 8:0 vendor: Crucial model: CT240M500SSD1
family: Micron Client SSDs size: 223.57 GiB block-size: physical: 4096 B
logical: 512 B sata: 3.1 speed: 6.0 Gb/s tech: SSD serial: <filter>
fw-rev: MU05 temp: 39 C scheme: GPT
SMART: yes state: enabled health: PASSED on: 5y 239d 13h cycles: 1553
written: 24.3 TiB
ID-2: /dev/sdb maj-min: 8:16 vendor: Crucial model: CT240M500SSD1
family: Micron Client SSDs size: 223.57 GiB block-size: physical: 4096 B
logical: 512 B sata: 3.1 speed: 6.0 Gb/s tech: SSD serial: <filter>
fw-rev: MU05 temp: 41 C scheme: GPT
SMART: yes state: enabled health: PASSED on: 6y 95d 7h cycles: 860
written: 41.41 TiB
ID-3: /dev/sdc maj-min: 8:32 vendor: Western Digital
model: WD10EALX-009BA0 family: Blue size: 931.51 GiB block-size:
physical: 512 B logical: 512 B sata: 3.0 speed: 6.0 Gb/s tech: N/A
serial: <filter> fw-rev: 1H15 temp: 39 C scheme: GPT
SMART: yes state: enabled health: PASSED on: 7y 3d 9h cycles: 2051
Partition:
ID-1: / raw-size: 223.27 GiB size: 223.27 GiB (100.00%)
used: 53.02 GiB (23.7%) fs: btrfs block-size: 4096 B dev: /dev/sdb2
maj-min: 8:18
ID-2: /boot/efi raw-size: 300 MiB size: 299.4 MiB (99.80%)
used: 27.4 MiB (9.1%) fs: vfat block-size: 512 B dev: /dev/sdb1
maj-min: 8:17
ID-3: /home raw-size: 223.27 GiB size: 223.27 GiB (100.00%)
used: 53.02 GiB (23.7%) fs: btrfs block-size: 4096 B dev: /dev/sdb2
maj-min: 8:18
ID-4: /var/log raw-size: 223.27 GiB size: 223.27 GiB (100.00%)
used: 53.02 GiB (23.7%) fs: btrfs block-size: 4096 B dev: /dev/sdb2
maj-min: 8:18
ID-5: /var/tmp raw-size: 223.27 GiB size: 223.27 GiB (100.00%)
used: 53.02 GiB (23.7%) fs: btrfs block-size: 4096 B dev: /dev/sdb2
maj-min: 8:18
Swap:
Kernel: swappiness: 133 (default 60) cache-pressure: 100 (default) zswap: no
ID-1: swap-1 type: zram size: 15.58 GiB used: 0 KiB (0.0%) priority: 100
comp: zstd avail: lzo,lzo-rle,lz4,lz4hc,842 max-streams: 4 dev: /dev/zram0
Sensors:
System Temperatures: cpu: 35.6 C mobo: N/A gpu: amdgpu temp: 43.0 C
Fan Speeds (rpm): N/A gpu: amdgpu fan: 1032
Info:
Memory: total: 16 GiB available: 15.58 GiB used: 4.85 GiB (31.1%)
Processes: 274 Power: uptime: 21m states: freeze,mem,disk suspend: deep
avail: s2idle wakeups: 0 hibernate: platform avail: shutdown, reboot,
suspend, test_resume image: 6.21 GiB services: org_kde_powerdevil,upowerd
Init: systemd v: 256 default: graphical tool: systemctl
Packages: pm: pacman pkgs: 1675 libs: 453 tools: octopi,pacseek,paru
Compilers: clang: 17.0.6 gcc: 14.1.1 Shell: garuda-inxi (sudo) default: Bash
v: 5.2.26 running-in: konsole inxi: 3.3.35
Garuda (2.6.26-1):
System install date:     2024-05-13
Last full system update: 2024-06-24
Is partially upgraded:   No
Relevant software:       snapper NetworkManager dracut
Windows dual boot:       Yes
Failed units:

If you want this to show up in your Fish shell, you shouldn’t add it to ~/.bashrc at all. The Fish shell does not source ~/.bashrc, so it just won’t work.

Instead, create a script and paste the example code. Then, run the script to confirm it is working as expected.

 ~ 
❯ micro weather-date-splash.sh

~ took 6s 
❯ chmod +x weather-date-splash.sh 

~ 
❯ ./weather-date-splash.sh 
Weather report: Edmonton                June 2024     
                                  Su Mo Tu We Th Fr Sa       08:35 am
       \   /     Sunny                               1
        .-.      +57(53) °F        2  3  4  5  6  7  8
     ― (   ) ―   → 6 mph           9 10 11 12 13 14 15
        `-’      6 mi             16 17 18 19 20 21 22
       /   \     0.0 in           22424 25 26 27 28 29
                                  30                  

Once you have confirmed the script is working properly, add a line to ~/.config/fish/config.fish that calls the script.

echo "~/weather-date-splash.sh" >> ~/.config/fish/config.fish

Then open a new Fish shell to confirm the call to the script is working as expected.

It looks like the calendar portion of the example code may need a little tweak to fix the highlighted date. Other than that it seems to be working as-is. :smiley:

6 Likes

Thanks that was very helpful, what do you think?

It looks like the highlighted date is off a little bit in your case as well. The script may need a small adjustment. Try changing the value of “tput cub” in this part of the script, until it matches up correctly:

while IFS= read -r Cal; do
    printf "%s" "$Cal"
    if [[ $CalLineCnt -gt 2 ]] ; then
        # See if today is on current line & invert background
        tput cub 22

Try changing it from 22 to something else, maybe 18 or 20.

To complete the effect with the clock you can install toilet or figlet.

sudo pacman -S toilet

Edit:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.