move tmux to $XDG_CONFIG_HOME

This commit is contained in:
Oliver Ladner 2024-02-08 16:01:45 +01:00
commit 2a0f219d33
8 changed files with 140 additions and 140 deletions

View file

@ -0,0 +1,21 @@
#!/usr/bin/env osascript
# Returns the current playing song in Spotify for OSX
tell application "Spotify"
if it is running then
if player state is playing then
set track_name to name of current track
set artist_name to artist of current track
if artist_name > 0
# If the track has an artist set and is therefore most likely a song rather than an advert
" ♫ " & artist_name & " - " & track_name
else
# If the track doesn't have an artist set and is therefore most likely an advert rather than a song
" ~ " & track_name
end if
else
" ⏸︎ Spotify is paused"
end if
end if
end tell

57
.config/tmux/tmux.conf Normal file
View file

@ -0,0 +1,57 @@
# Source changes without restarting tmux:
# tmux source-file ~/.tmux.conf
# I have a custom Planck EZ layer for tmux
# so I don't have to adjust keyboard shortcuts
#
# Still, the most important ones to me:
# Prefix is Ctrl+b, then:
# c create new window
# n switch to next window
# <n> switch to windows <n>
# o switch to next pane
# % split pane vertically
# " split pane horizontally
# <Space> change layout when having more than one pane
# , rename active window
# I don't know
set -g mouse on
# Increase scrollback history
set-option -g history-limit 50000
# Faster mouse scrolling
set -g @scroll-speed-num-lines-per-scroll 5
# Vi mode to copy things from terminal
setw -g mode-keys vi
# Count panes from 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1
# Status bar stuff
set -g status-style fg=#9d7cd8,bg=#16161e
set-window-option -g window-status-current-style bg=#3e3158
set -g status-position top
set -g status-interval 10
set -g status-left "#( ~/.config/tmux/tmux_left.sh )"
set -g status-left-length 60
set -g status-justify centre
set -g status-right "#( ~/.config/tmux/tmux_right.sh )"
set -g status-right-length 60
# Get good colors
# https://www.reddit.com/r/tmux/comments/mesrci/tmux_2_doesnt_seem_to_use_256_colors/
#set-option -g default-terminal "screen-256color"
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"
set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
set-environment -g COLORTERM "truecolor"
# Display messages longer (ms)
#set-option -g display-time 4000
# Splits start with $PWD from source pane
bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"

6
.config/tmux/tmux_left.sh Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
# Trigger Applescript when on macOS
if [[ "$OSTYPE" == "darwin"* ]]; then
~/git/dotfiles/.config/tmux/spotify.applescript
fi

56
.config/tmux/tmux_right.sh Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# This doesn't show overall/summarized CPU usage as e.g. macOS Activity Monitor
# But still capable of showing high/multicore process CPU usage
cpu_usage=$(ps -Ac -o %cpu,comm | sort -nk1 | grep -vE "(top)" | tail -1)
float=$(echo "$cpu_usage" | awk '{print $1}')
cpu_percent=${float%.*}
cpu_procname=$(echo "$cpu_usage" | awk '{print $2,$3,$4}')
# nettop needs at least two samples (-L 2) to calculate a delta
# the beasty awk then throws away the first 50% samples (n=50) with bogus
# data and sorts it by bytes_in
bandwidth=$(nettop -t wifi -P -J bytes_in,bytes_out -d -x -L 2 \
| grep -v '^time' | sort -k1 | awk -v n=50 '{a[FNR]=$0; \
min=FNR-int(FNR*n/100)} {i=min; while(i in a) delete a[i--]} \
END{for(i=min+1;i<=FNR;++i) print a[i]}' - | sed 's/,$//' \
| sed 's#\.[0-9]*##g' | sort -t',' -k 3 -n | tail -1 | \
awk -F',' '{print $3,$4,$2}')
value=$(echo "$bandwidth" | awk '{print $1}')
if [ "$value" -lt 1000 ]; then
bw_down=$(echo "$value" | awk '{print int($1),"B/s"}')
elif [ "$value" -ge 1000 ] && [ "$value" -lt 1000000 ]; then
bw_down=$(echo "$value" | awk '{print int($1/1000),"kB/s"}')
elif [ "$value" -ge 1000000 ]; then
bw_down=$(echo "$value" | awk '{print int($1/1000^2),"MB/s"}')
fi
value=$(echo "$bandwidth" | awk '{print $2}')
if [ "$value" -lt 1000 ]; then
bw_up=$(echo "$value" | awk '{print int($2),"B/s"}')
elif [ "$value" -ge 1000 ] && [ "$value" -lt 1000000 ]; then
bw_up=$(echo "$value" | awk '{print int($2/1000),"kB/s"}')
elif [ "$value" -ge 1000000 ]; then
bw_up=$(echo "$value" | awk '{print int($2/1000^2),"MB/s"}')
fi
bw_procname=$(echo "$bandwidth" | awk '{print $3,$4,$5}')
# Pings the default gateway and returns avg ping. Three ping counts
# recommended for a reasonably meaningful average
ping=$(ping -t 2 -q -c 3 "$(route -n get default | \
awk '$1 ~ "gateway:" {print $2}')" | \
awk -F'/' '$1 ~ "round-trip" {print int($5)}')
# cpu load 4 digits max, smaller value is padded
# cpu process name right padded
cpu=$(printf "%4d%% %#-14.14s" "$cpu_percent" "$cpu_procname")
# up/download 8 digits max each, pad smaller value (has units baked in)
# process name right padded
bandwidth=$(printf "↓%8s ↑%8s %#-14.14s" "$bw_down" "$bw_up" "$bw_procname")
# cpu load 4 digits max, smaller value is padded
ping=$(printf "%4dms " "$ping")
# Combine all printf formatted metrics
echo "$ping $bandwidth $cpu"