h1romas4 / zellij-datetime

This plugin adds a date and time pane to [Zellij](https://zellij.dev/), a terminal workspace.
https://another.maple4ever.net/archives/3271/
MIT License
24 stars 3 forks source link
rust wasi wasmer webassemby zellij zellij-plugin

zellij-datetime

This plugin adds a date and time pane to Zellij, a terminal workspace.

zellij-08.png

Zellij's plugin system leverages WebAssembly/WASI, and this plugin will also work with both amd64 and Arm in the same binary.

Require

$ zellij -V
zellij 0.41.1

Setup

Preparation of Plug-in deployment destination:

# create configuration directory
mkdir -p ~/.config/zellij/layouts/
mkdir -p ~/.config/zellij/plugins/
# If you have already created a layout file, you do not need to do the following.
# export default layout (Be careful not to overwrite your settings)
zellij setup --dump-layout default > ~/.config/zellij/layouts/default.kdl

Download zellij-datetime.wasm:

cd ~/.config/zellij/plugins/
# download datetime plugin
wget -O zellij-datetime.wasm \
    https://github.com/h1romas4/zellij-datetime/releases/latest/download/zellij-datetime.wasm

Set the full path to zellij-datetime.wasm in the ~/.config/zellij/layouts/default.kdl layouts file.

vi ~/.config/zellij/layouts/default.kdl

Example - Basic layout:

layout {
    pane size=1 borderless=true {
        plugin location="file:/home/hiromasa/.config/zellij/plugins/zellij-datetime.wasm"
    }
    pane size=1 borderless=true {
        plugin location="zellij:tab-bar"
    }
    pane
    pane size=2 borderless=true {
        plugin location="zellij:status-bar"
    }
}

Example - The same line as the other bar(s):

layout {
    pane size=1 split_direction="vertical" {
        pane size="75%" borderless=true {
            plugin location="zellij:tab-bar"
        }
        pane size="25%" borderless=true {
            plugin location="file:/home/hiromasa/.config/zellij/plugins/zellij-datetime.wasm"
        }
    }
    pane
    pane size=2 borderless=true {
        plugin location="zellij:status-bar"
    }
}

Usage

https://github.com/h1romas4/zellij-datetime/assets/4337664/6ba30ce8-f1c5-4c32-9d00-18e2224b4c37

Plugin settings

layout {
    pane size=1 borderless=true {
        plugin location="file:/home/hiromasa/.config/zellij/plugins/zellij-datetime.wasm" {
            timezone1 "PDT/-9"
            timezone2 "UTC/0"
            timezone3 "CEST/+2"
            timezone4 "JST/+9"
            timezone5 "NPT/+5.75"
            default_timezone "JST"
            date_format "%Y/%m/%d %A"
            time_format "%I:%M %p"
            background_color "#0080a0"
            foreground_color "#ffffff"
            pane_color "#1e1e1e"
            enable_right_click false
            arrow_separator1 ""
            arrow_separator2 ""
            arrow_separator3 ""
            padding_adjust 0
            text_align "right"
        }
    }
}
Key Format Default Note
timezone1 "name/offset" "UTC/0"
timezone[2-9] "name/offset" -
default_timezone "name" "UTC"
date_format chrono::format::strftime "%Y-%m-%d %a"
time_format chrono::format::strftime "%H:%M" The screen refreshes every minute.
background_color "#color" "#0080a0"
foreground_color "#color" "#ffffff" It may be adjusted automatically depending on the background_color.
pane_color "#color" "#1e1e1e"
enable_right_click bool false Right-clicking on the clock outputs the string format to stdin; Allow PermissionType::WriteToStdin permission when starting the plugin.
arrow_separator1 "string" "" Delimiter string on line. Only the first character.
arrow_separator2 "string" "" 📅 Only the first character.
arrow_separator3 "string" "" ⌚ Only the first character.
padding_adjust i32 0 It can be used to adjust left-justified padding. For example, adjusting the separator width if it is off by full-width.
text_align "string" "right" right or left or center

Build

Development

# If you don't have Zellij installed already
cargo install --locked zellij
# Git clone
git clone https://github.com/h1romas4/zellij-datetime
cd zellij-datetime
# Building the plugin
cargo build
# Running in Zellij
zellij -l plugin.kdl

Production

# Install wasm-snip
cargo install wasm-snip
# Build
cargo build --release
# Remove debug symbols and replaces unreachable.
wasm-snip target/wasm32-wasip1/release/zellij-datetime.wasm -o target/wasm32-wasip1/release/zellij-datetime-snip.wasm
# Deploy plugin directory
cp -p target/wasm32-wasip1/release/zellij-datetime-snip.wasm ~/.config/zellij/plugins/zellij-datetime.wasm
# Running in Zellij
zellij

Development on Ubuntu 22.04 with container

git clone https://github.com/zellij-org/zellij.git
git clone https://github.com/h1romas4/zellij-datetime
# build Zellij (A newer version of protobuf-compiler is required)
cd zellij
cargo xtask build --release
# build zellij-datetime
cd ../zellij-datetime
cargo build
# Run with container (podman or docker)
podman run \
    --name zellij-datetime \
    --env SHELL=/usr/bin/bash \
    -v ../zellij/target/release/:/opt/zellij \
    -v .:/opt/zellij-datetime \
    -w /opt/zellij-datetime \
    -it --rm \
    mcr.microsoft.com/devcontainers/base:ubuntu-22.04 \
    /opt/zellij/zellij -l plugin.kdl

License

MIT License

WIP