diff --git a/pre-install.sh b/bin/pre-install.sh similarity index 100% rename from pre-install.sh rename to bin/pre-install.sh diff --git a/bin/tmux_mem_cpu_load.sh b/bin/tmux_mem_cpu_load.sh new file mode 100755 index 0000000..cac3a06 --- /dev/null +++ b/bin/tmux_mem_cpu_load.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd $HOME/.dotfiles/tmux/plugins/tmux-mem-cpu-load +cmake . +make +sudo make install diff --git a/bin/weather/go.mod b/bin/weather/go.mod new file mode 100644 index 0000000..d8d9456 --- /dev/null +++ b/bin/weather/go.mod @@ -0,0 +1,3 @@ +module weather + +go 1.18 diff --git a/bin/weather/main.go b/bin/weather/main.go new file mode 100644 index 0000000..5cba88f --- /dev/null +++ b/bin/weather/main.go @@ -0,0 +1,84 @@ +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "os/exec" + "strings" +) + +type Weather struct { + Temp float64 + Humidity int + Icon rune +} + +func (w *Weather) String() string { + return fmt.Sprintf("%c %.1f%cF %d%%", w.Icon, w.Temp, '\u00B0', w.Humidity) // Output as ICON ##.#*F ##% where the rune is a degree sign +} + +func main() { + weathercmd := exec.Command("sh", "-c", "${HOME}/.dotfiles/bin/weather/weather.sh") + var out bytes.Buffer + weathercmd.Stdout = &out + if err := weathercmd.Run(); err != nil { + panic(err) + } + // parsing json time :D + var temp map[string]interface{} + if err := json.Unmarshal(out.Bytes(), &temp); err != nil { + panic(err) + } + // fmting hell + weather := &Weather{} + for k, v := range temp { + if k == "main" { + // weather info + for nk, nv := range v.(map[string]interface{}) { + if nk == "temp" { + weather.Temp = nv.(float64) + } else if nk == "humidity" { + weather.Humidity = int(nv.(float64)) // this is as gross as it gets + } + } + } else if k == "weather" { + m := v.([]interface{}) + for nk, nv := range m[0].(map[string]interface{}) { + if nk == "icon" { + weather.Icon = getIcon(nv.(string)) + } + } + } + } + fmt.Print(weather) +} + +func getIcon(code string) rune { + weather := strings.Trim(code, "nd") // trimming day or night tag + switch weather { + case "01": + // clear skys + return '\u263C' // sun code + case "02", "03": + // few clouds and scattered + return '\U0001F324' // small clouds with sun + case "04": + // broken clouds + return '\U0001F325' // big clouds with sun + case "09", "10": + // rain + return '\U0001F327' // cloud with rain + case "11": + // thunderstorm + return '\U0001F329' // thunderstorm cloud + case "13": + // snow + return '\U0001F328' // snow cloud + case "50": + // mist + return '\U0001F32B' // fog + default: + return '\uFFFD' // question mark + } +} diff --git a/bin/weather/weather b/bin/weather/weather new file mode 100755 index 0000000..4182049 Binary files /dev/null and b/bin/weather/weather differ diff --git a/bin/weather/weather.sh b/bin/weather/weather.sh new file mode 100755 index 0000000..381689d --- /dev/null +++ b/bin/weather/weather.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# if you get my email banned ill freak out +API_KEY='60844f78595f66ff8e94df50aed24397' + +LOCATION=$(curl --silent http://ip-api.com/csv) +CITY=$(echo "$LOCATION" | cut -d , -f 6) +LAT=$(echo "$LOCATION" | cut -d , -f 8) +LON=$(echo "$LOCATION" | cut -d , -f 9) +# getting weather +WEATHER=$(curl --silent http://api.openweathermap.org/data/2.5/weather\?lat="$LAT"\&lon="$LON"\&appid="$API_KEY"\&units=imperial) +echo $WEATHER diff --git a/install.conf.yaml b/install.conf.yaml index 4d70b08..268f6c4 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -27,4 +27,4 @@ - [cp ./vim/hybrid/colors/hybrid.vim ./vim/colors/hybrid.vim, Setting up theme] - [tmux/plugins/tpm/bin/install_plugins, Installing Tmux Plugins] - [tmux/plugins/tpm/bin/update_plugins all, Updating Tmux Plugins] - + - [bin/tmux_mem_cpu_build.sh, Building tmux-mem-cpu-load] diff --git a/tmux.conf b/tmux.conf index 2558f75..ee84990 100644 --- a/tmux.conf +++ b/tmux.conf @@ -7,8 +7,8 @@ set -g history-limit 10000 # Set display time to be longer to allow selecting set -g display-panes-time 5000 -# fix headless issue hopefully -set-window-option -g aggressive-resize +# setup automatic renaming +set -g automatic-rename on # setting up TPM set -g @plugin 'tmux-plugins/tpm' @@ -21,6 +21,8 @@ set -g @plugin 'thewtex/tmux-mem-cpu-load' set -g status-interval 1 set -g status-right "#[bg=black]#(~/.tmux/plugins/tmux-mem-cpu-load/tmux-mem-cpu-load -p -i 1 -a 1)#[default] %a %l:%M " set -g status-right-length 100 +set -g status-left "#(~/.dotfiles/bin/weather/weather)#[default] " + # tmux auto start set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum'