Skip to content

chmouel/batzconverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

99 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

batzconverter - Batman Timezone Converter

Show times in different timezone with bash

Blog post

https://blog.chmouel.com/2021/01/31/batzconverter-a-multiple-timezone-converter/

Demo

See screenshot

INSTALL

grab the shell script directly from this repo and put it in your path, or just copy and paste this :

#  will try to install in /usr/local if you have the right or $HOME/.local/bin need to be in your path
dest="/usr/local/bin"
[[ -w ${dest} ]] || { dest=${HOME}/.local/bin;mkdir -p ${dest} ;}
curl -f -L -o ${dest}/batz https://raw.githubusercontent.com/chmouel/batzconverter/master/batz.sh && \
        chmod +x ${dest}/batz && \
 echo "'The' batz has been installed into: ${dest}/batz"

Settings

Create a file in ~/.config/batz/config and add configure the TIME_ZONES and TIME_ZONES_EMOJI variable like this :

## Change the default timezones here!
TIME_ZONES=(
  ["India"]="Asia/Calcutta"
  ["Europe"]="Europe/Paris"
  ["US-East"]="America/New_York"
  ["US-West"]="America/Los_Angeles"
)

TIME_ZONES_EMOJI=(
 ["India"]="๐Ÿ‡ฎ๐Ÿ‡ณ "
 ["Europe"]="๐Ÿ‡ช๐Ÿ‡บ "
 ["US-East"]="๐Ÿ‡บ๐Ÿ‡ธ "
 ["US-West"]="๐Ÿป"
)

DATE_FORMAT="%b %Hh%M"
DATE_FORMAT_PADDING=10
DEFAULT_TIME_ZOME_EMOJI="๐ŸŒ"

The format is :

"TZ_Alias_Name"="Timezone"

for example :

"HomeSweetHome"="Europe/Paris"

You can look an example in my config here

Requirement

Some pretty modern Bash >4.0 and modern GNU Date. On MacosX install those from brew (bash and gnuutils).

Usage

% batz
% batz 10h30
% batz 10h30 next week
% batz 11:00 next thursday

BaTZ will show all different timezone for the timeformat

You can as well add multiple timezones directly on the command line like this :

% batz +America/Chicago +UTC 10h00 tomorrow

If you don't know the timezone and you have the fzf utility installed you can use the -f option to select interactively the timezone. You can select multiple timezone by using the TAB key in fzf.

By default this script will try to detect your current timezone, if you want to say something like this: show me the different times tomorrow if I were at 10h00 AM on UTC timezone, you can do :

% batz -t UTC 10h00

When you set another timezone than your current one, it wil show a nice โœˆ๏ธemoji near your different base timezone, or by default it will show a ๐Ÿ  emojis to emphasis the current timezone in your copy and paste.

If you want to add extra timezone with +TZ you need to do at first before the options, cause bash getopt is kind of buggy in this regard

You can use the -j option to output as json and may do some parsing with it. (this is used by the Alfred suppoort).

If you have the gum utility installed you can use the flag -g to show the timezone using the gum tables You can as well set USE_GUM=1 in your config file to set it as default.

The output looks for example like this for me:

image

You can add the -n argument to batz to not show any colours or emojis. It will respect the NO_COLOUR environment variable as well.

Rofi Support

Take this rofi script rofibatz.sh and place it somewhere, i.e: ~/.config/rofi/rofibatz.sh, launch it up like this :

rofi -modi batz:${HOME}/.config/rofi/rofibatz.sh -show batz

You can type batz string i.e: 13h00 tomorrow when you press enter it will evaluate it.

I have a custom theme so your mileage may vary but for me it will be shown like this :

See screenshot

Wofi Support

Screenshot_2021-11-23-23:24 03

Just do something like this assuming you have wofi and wl-copy installed :

wl-copy $(batz|sed -e "s/\x1b\[.\{1,5\}m//g"|wofi -d|sed 's/.* : //')

will only get you the timezone since wofi doesnt support scripts (afaik)

Alfred Support

BaTZ support alfred, it basically output nicely the timezone from alfred in a nice way.

See screenshot

Just install the alfredworlflow file from the repository and make sure the batz script is in one of these path: $HOME/bin/ or /usr/local/bin/

Zenity support

output=$(zenity --entry --text "๐Ÿฆ‡Time" --entry-text $(date ''+%H:%M''));[[ -n $output ]] && batz $output|wl-copy',

Copyright

Apache-2.0

Authors

Chmouel Boudjnah <@chmouel>