Last active
December 29, 2020 19:42
-
-
Save sebastianvera/becc3c8572c95324a0170df092215eef to your computer and use it in GitHub Desktop.
My tmux config, heavy influenced by https://github.com/simonsmith/dotfiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tmux prefix | |
unbind C-b | |
set -g prefix C-a | |
# set -g default-terminal "xterm-256color" | |
set -g default-terminal "screen-256color" | |
set -ga terminal-overrides ",xterm-256color:Tc" | |
# Enable true color - tmux 2.2+ | |
# https://deductivelabs.com/en/2016/03/using-true-color-vim-tmux/ | |
# set-option -ga terminal-overrides ",xterm-256color:Tc" | |
# 0 is too far | |
set -g base-index 1 | |
setw -g pane-base-index 1 | |
setw -g mouse on | |
setw -g monitor-activity off | |
setw -g mode-keys vi | |
# Set vim style copy paste | |
bind-key -T copy-mode-vi 'v' send-keys -X begin-selection | |
bind-key -T copy-mode-vi 'V' send-keys -X select-line | |
bind-key -T copy-mode-vi 'r' send-keys -X rectangle-toggle | |
# = = = = = = = = | |
# disable "release mouse drag to copy and exit copy-mode", ref: https://github.com/tmux/tmux/issues/140 | |
set -g @yank_with_mouse off # or 'on' | |
unbind-key -T copy-mode-vi MouseDragEnd1Pane | |
# since MouseDragEnd1Pane neither exit copy-mode nor clear selection now, | |
# let single click do selection clearing for us. | |
bind-key -T copy-mode-vi MouseDown1Pane select-pane\; send-keys -X clear-selection | |
# this line changes the default binding of MouseDrag1Pane, the only difference | |
# is that we use `copy-mode -eM` instead of `copy-mode -M`, so that WheelDownPane | |
# can trigger copy-mode to exit when copy-mode is entered by MouseDrag1Pane | |
bind -n MouseDrag1Pane if -Ft= '#{mouse_any_flag}' 'if -Ft= \"#{pane_in_mode}\" \"copy-mode -eM\" \"send-keys -M\"' 'copy-mode -eM' | |
# = = = = = = = = | |
# resize panes | |
bind -r H resize-pane -L 5 | |
bind -r J resize-pane -D 5 | |
bind -r K resize-pane -U 5 | |
bind -r L resize-pane -R 5 | |
# create window and panes | |
bind c new-window -c "#{pane_current_path}" | |
bind | split-window -h -c "#{pane_current_path}" | |
bind - split-window -v -c "#{pane_current_path}" | |
# Restore clear screen | |
bind C-l send-keys 'C-l' | |
# ctrl+] => cmd+k (iTerm, send keys: cmd+k => 0x1d) | |
bind -n C-] send-keys -R \; send-keys C-l \; clear-history | |
# status | |
set -g @prefix_highlight_show_copy_mode 'on' | |
set -g @prefix_highlight_copy_mode_attr 'fg=colour231,bg=colour04' # default is 'fg=default,bg=yellow' | |
# Plugins | |
set -g @plugin 'tmux-plugins/tpm' | |
set -g @plugin 'tmux-plugins/tmux-sensible' | |
set -g @plugin 'tmux-plugins/tmux-prefix-highlight' | |
set -g @plugin 'tmux-plugins/tmux-copycat' | |
set -g @plugin 'tmux-plugins/tmux-yank' | |
set -g @plugin 'tmux-plugins/tmux-open' | |
set -g @plugin 'christoomey/vim-tmux-navigator' | |
# Theme | |
source ~/.tmuxline_snapshot | |
run -b '~/.tmux/plugins/tpm/tpm' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -g status-justify "left" | |
set -g status "on" | |
set -g status-right-length "160" | |
set -g status-right-style "none" | |
set -g message-style fg=colour2 | |
set -g message-style bg=colour0 | |
set -g status-style "none" | |
set -g status-style bg=default | |
set -g pane-border-style bg=default | |
set -g pane-border-style fg=colour240 | |
set -g pane-active-border-style bg=default | |
set -g pane-active-border-style fg=colour245 | |
set -g status-left-length "100" | |
set -g status-left-style "none" | |
setw -g window-status-style bg=default | |
setw -g window-status-style fg=colour242 | |
setw -g window-status-style "none" | |
setw -g window-status-activity-style "none" | |
setw -g window-status-activity-style fg=colour2 | |
setw -g window-status-separator "" | |
set -g status-left "#[fg=colour231] #S #[fg=colour2,nobold,nounderscore,noitalics]" | |
set -g status-right "#{prefix_highlight} #[fg=colour0,nobold,nounderscore,noitalics] #[fg=colour242] #(spotify) #(ipconfig getifaddr en0) | #(battery -a -p -t) #[fg=colour242]| %R - %d-%m-%Y" | |
setw -g window-status-format "#[fg=colour0,nobold,nounderscore,noitalics] #[fg=colour242] #W #[fg=colour0,nobold,nounderscore,noitalics]" | |
setw -g window-status-current-format "#[fg=colour0,nobold,nounderscore,noitalics] #[fg=colour04] #W #[fg=colour0,nobold,nounderscore,noitalics]" | |
setw -g window-status-current-style "bright" | |
setw -g window-status-current-style bg=default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() { | |
cat <<EOF | |
battery: usage: | |
general: | |
-h, --help print this message | |
-p use pmset (more accurate) | |
-t output tmux status bar format | |
-a output ascii bar instead of spark's | |
-b battery path default: /sys/class/power_supply/BAT0 | |
colors: | |
-g <color> good battery level default: green or 1;32 | |
-m <color> middle battery level default: yellow or 1;33 | |
-w <color> warn battery level default: red or 0;31 | |
EOF | |
} | |
if [[ $1 == '-h' || $1 == '--help' || $1 == '-?' ]]; then | |
usage | |
exit 0 | |
fi | |
# For default behavior | |
setDefaults() { | |
pmset_on=0 | |
output_tmux=0 | |
ascii=0 | |
ascii_bar='==========' | |
good_color="1;32" | |
middle_color="1;33" | |
warn_color="0;31" | |
connected=0 | |
battery_path=/sys/class/power_supply/BAT0 | |
} | |
setDefaults | |
battery_charge() { | |
case $(uname -s) in | |
"Darwin") | |
if ((pmset_on)) && hash pmset 2>/dev/null; then | |
if [ "$(pmset -g batt | grep -o 'AC Power')" ]; then | |
BATT_CONNECTED=1 | |
else | |
BATT_CONNECTED=0 | |
fi | |
BATT_PCT=$(pmset -g batt | grep -o '[0-9]*%' | tr -d %) | |
else | |
while read key value; do | |
case $key in | |
"MaxCapacity") | |
maxcap=$value;; | |
"CurrentCapacity") | |
curcap=$value;; | |
"ExternalConnected") | |
if [ $value == "No" ]; then | |
BATT_CONNECTED=0 | |
else | |
BATT_CONNECTED=1 | |
fi | |
;; | |
esac | |
if [[ -n "$maxcap" && -n $curcap ]]; then | |
BATT_PCT=$(( 100 * curcap / maxcap)) | |
fi | |
done < <(ioreg -n AppleSmartBattery -r | grep -o '"[^"]*" = [^ ]*' | sed -e 's/= //g' -e 's/"//g' | sort) | |
fi | |
;; | |
"Linux") | |
battery_state=$(cat $battery_path/status) | |
battery_full=$battery_path/charge_full | |
battery_current=$battery_path/charge_now | |
if [ $battery_state == 'Discharging' ]; then | |
BATT_CONNECTED=0 | |
else | |
BATT_CONNECTED=1 | |
fi | |
now=$(cat $battery_current) | |
full=$(cat $battery_full) | |
BATT_PCT=$((100 * $now / $full)) | |
;; | |
esac | |
} | |
# Apply the correct color to the battery status prompt | |
apply_colors() { | |
if [[ $BATT_PCT -ge 95 ]]; then | |
if ((output_tmux)); then | |
COLOR="#[fg=$good_color]Batt: " | |
else | |
COLOR=$good_color | |
fi | |
# Green | |
elif [[ $BATT_PCT -ge 75 ]]; then | |
if ((output_tmux)); then | |
COLOR="#[fg=$good_color]Batt: " | |
else | |
COLOR=$good_color | |
fi | |
# Yellow | |
elif [[ $BATT_PCT -ge 20 ]] && [[ $BATT_PCT -lt 75 ]]; then | |
if ((output_tmux)); then | |
COLOR="#[fg=$middle_color]Batt: " | |
else | |
COLOR=$middle_color | |
fi | |
# Red | |
elif [[ $BATT_PCT -lt 20 ]]; then | |
if ((output_tmux)); then | |
COLOR="#[fg=$warn_color]Batt: " | |
else | |
COLOR=$warn_color | |
fi | |
fi | |
} | |
print_status() { | |
# Print the battery status | |
if ((BATT_CONNECTED)); then | |
GRAPH="" | |
else | |
if hash spark 2>/dev/null; then | |
sparks=$(spark 0 ${BATT_PCT} 100) | |
GRAPH=${sparks:1:1} | |
else | |
ascii=1 | |
fi | |
fi | |
if ((ascii)); then | |
barlength=${#ascii_bar} | |
# Divides BATTTERY_STATUS by 10 to get a decimal number; i.e 7.6 | |
n=$(echo "scale = 1; $BATT_PCT / 10" | bc) | |
# Round the number to the nearest whole number | |
rounded_n=$(printf "%.0f" "$n") | |
# Creates the bar | |
GRAPH=$(printf "[%-${barlength}s]" "${ascii_bar:0:rounded_n}") | |
fi | |
if ((output_tmux)); then | |
printf "%s" "$COLOR" "$BATT_PCT%" | |
else | |
printf "\e[0;%sm%s %s \e[m\n" "$COLOR" "[$BATT_PCT%]" "$GRAPH" | |
fi | |
} | |
# Read args | |
while getopts ":g:m:w:tab:p" opt; do | |
case $opt in | |
g) | |
good_color=$OPTARG | |
;; | |
m) | |
middle_color=$OPTARG | |
;; | |
w) | |
warn_color=$OPTARG | |
;; | |
t) | |
output_tmux=1 | |
good_color="green" | |
middle_color="yellow" | |
warn_color="red" | |
;; | |
a) | |
ascii=1 | |
;; | |
p) | |
pmset_on=1 | |
;; | |
b) | |
if [ -d $OPTARG ]; then | |
battery_path=$OPTARG | |
else | |
>&2 echo "Battery not found, trying to use default path..." | |
if [ ! -d $battery_path ]; then | |
>&2 echo "Default battery path is also unreachable" | |
exit 1 | |
fi | |
fi | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument" | |
exit 1 | |
;; | |
esac | |
done | |
battery_charge | |
apply_colors | |
print_status | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
music=$(osascript ~/applescript/spotify.scpt) | |
if [[ $music ]]; then | |
echo "$music |" | |
fi; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if application "Spotify" is running then | |
tell application "Spotify" | |
set theName to name of the current track | |
set theArtist to artist of the current track | |
set theAlbum to album of the current track | |
set theUrl to spotify url of the current track | |
set playerState to player state | |
if playerState is playing then | |
set playIcon to "Playing:" | |
end if | |
if playerState is paused then | |
set playIcon to "Paused:" | |
end if | |
try | |
return playIcon & " " & theName & " by " & theArtist | |
on error err | |
end try | |
end tell | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment