Skip to content

Instantly share code, notes, and snippets.

@elzii
Created July 6, 2017 01:33
Show Gist options
  • Save elzii/04459f122571f61803a8459758f2e016 to your computer and use it in GitHub Desktop.
Save elzii/04459f122571f61803a8459758f2e016 to your computer and use it in GitHub Desktop.
Sloppy tmux config
# ███ ▄▄▄▄███▄▄▄▄ ███ █▄ ▀████ ▐████▀
# ▀█████████▄ ▄██▀▀▀███▀▀▀██▄ ███ ███ ███▌ ████▀
# ▀███▀▀██ ███ ███ ███ ███ ███ ███ ▐███
# ███ ▀ ███ ███ ███ ███ ███ ▀███▄███▀
# ███ ███ ███ ███ ███ ███ ████▀██▄
# ███ ███ ███ ███ ███ ███ ▐███ ▀███
# ███ ███ ███ ███ ███ ███ ▄███ ███▄
# ▄████▀ ▀█ ███ █▀ ████████▀ ████ ███▄
# ============================================================================
# General settings
# ============================================================================
set-option -g default-shell /bin/zsh
set-option -g default-command /bin/zsh
# address vim mode switching delay (http://superuser.com/a/252717/65504)
set -sg escape-time 0
# show session name in tab title
set-option -g set-titles on
set-option -g set-titles-string "[tmux] #T @ #H"
# clipboard
set -g set-clipboard on
# don't automatically rename windows
set-option -g allow-rename off
# turn down the timeout for repeat commands
set-option -g repeat-time 150
# enable mouse mode
set -g mouse on
# Epic mouse control!
# can use better-mouse-mode plugin instead
bind -T root WheelUpPane if -F -t = "#{mouse_any_flag}" "send-keys -M" "select-pane -t =; if -F -t = \"#{alternate_on}\" \"send-keys Up Up\" \"copy-mode -e; send-keys -M\""
bind -T root WheelDownPane if -F -t = "#{mouse_any_flag}" "send-keys -M" "select-pane -t =; if -F -t = \"#{alternate_on}\" \"send-keys Down Down\" \"copy-mode -e; send-keys -M\""
# Fix cursor shape in vim
set -g -a terminal-overrides ',*:Ss=\E[%p1%d q:Se=\E[2 q'
# Copy-mode
set-window-option -g mode-keys vi
bind-key v copy-mode \; display "Copy mode!"
bind-key C-v copy-mode \; display "Copy mode!"
# paste buffer
bind-key p paste-buffer
# Make pbcopy/pbpaste and Vim's * register work.
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
unbind-key -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"
# bind -t vi-copy WheelUpPane halfpage-up
# bind -t vi-copy WheelDownPane halfpage-down
# unbind -t vi-copy MouseDragEnd1Pane
bind -t vi-copy MouseDown1Pane clear-selection
# default terminal
# set-option -ga terminal-overrides ",*256col*:Tc"
set -g default-terminal "screen-256color"
# increase scrollback buffer size
set -g history-limit 50000
# refresh 'status-left' and 'status-right' more often
set -g status-interval 1
# tmux messages are displayed for 4 seconds
set -g display-time 2000
# super useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on
# set-window-option -g aggressive-resize
# enable xterm keys
set-option -g xterm-keys on
# start window numbers from 1
set-option -g base-index 1
set-window-option -g pane-base-index 1
# renumber windows after a change
set-option -g renumber-windows on
# fix copying in tmux
set-option -g default-command "reattach-to-user-namespace -l zsh"
# emacs or vi style keybindings
set -g status-keys emacs
# focus events enabled for terminals that support them
set -g focus-events on
# status position
set-option -g status-position top
# ============================================================================
# Keys
# ============================================================================
# unbinds
unbind C-b
unbind C-a
unbind %
unbind ,
unbind .
unbind n
unbind p
unbind [
unbind '"'
unbind l
unbind &
unbind "'"
unbind-key C-h
unbind-key C-j
unbind-key C-k
unbind-key C-l
# reload config file
bind r source-file ~/.tmux.conf \; display-message "Reloaded"
# split panes using | and -
bind | split-window -h -c "#{pane_current_path}"
bind \ split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# look up in a man-page
bind-key m command-prompt -p "Man:" "split-window 'man %%'"
# swap window to top (first position in statusbar)
# TAGS: rotate
bind-key [ swap-window -t -1
bind-key ] swap-window -t +1
bind-key < swap-window -t -1
bind-key > swap-window -t +1
# move between windows
bind-key -n M-S-Left previous-window
bind-key -n M-S-Right next-window
bind-key -n M-Left previous-window
bind-key -n M-Right next-window
# resize pane
bind-key -n C-S-Up resize-pane -U 2
bind-key -n C-S-Down resize-pane -D 2
bind-key -n C-S-Left resize-pane -L 2
bind-key -n C-S-Right resize-pane -R 2
# break pane
bind-key b break-pane
# refresh client
bind-key R confirm-before refresh-client
# rename window
bind-key n command-prompt 'rename-window %%'
# rename session
bind-key N command-prompt 'rename-session %%'
# kill/close pane
bind-key x kill-pane
bind-key w kill-pane
# kill window
bind-key X kill-window
# kill session
bind-key q confirm-before kill-session
# choose window
bind-key W choose-window
# prefix
set -g prefix C-Space
bind-key C-Space send-prefix
# ============================================================================
# Theme
# ============================================================================
set-window-option -g monitor-activity on
set-window-option -g window-status-current-bg yellow
set-option -g message-fg colour235
# status bar
set-option -g status-justify left
set-option -g status-bg colour236
set-option -g status-interval 60
# status left
set-option -g status-left '#[bg=colour235]#[fg=colour12]  #(~/.tmux/bin/panes) '
set-option -g status-left-length 80
# style prefixes
STYLES_IP='#[bg=colour235]#[fg=colour7] '
STYLES_WIFI='#[bg=colour234]#[fg=colour13] '
STYLES_BATTERY='#[bg=colour233] '
# status right
set-option -g status-right '#{prefix_highlight} #{STYLES_IP} #(~/.tmux/bin/ip) #{STYLES_WIFI} #(~/.tmux/bin/wifi) #{STYLES_BATTERY} #(~/.tmux/bin/battery --tmux)#{STYLES_BATTERY} '
set-option -g status-right-length 80
# panes
set -g pane-active-border-bg 0
set -g pane-active-border-fg colour214
set -g pane-border-fg colour236
# window
set-window-option -g window-status-format '#[bg=colour237]#[fg=colour243] #I #[fg=colour194]#W '
# active window
set-window-option -g window-status-current-format '#[bg=colour235]#[fg=colour215] #I #[bg=colour235]#[fg=colour167]#W '
## set window notifications
set-option -g visual-activity off
set-window-option -g monitor-activity off
set-window-option -g automatic-rename on
# ============================================================================
# Plugins
# ============================================================================
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'eugene-eeo/tmux-badges'
run '~/.tmux/plugins/tpm/tpm'
  • install TPM first with git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
  • the font is custom patched, replace with emojis, unicode, whatever
  • put shell scripts in ~/.tmux/bin
#!/bin/bash
has() { type "$1" &>/dev/null; }
# If the current_bat is less than the BATTERY_DANGER,
# output color will be red
BATTERY_DANGER=20
# get_battery returns remaining battery
get_battery() {
local current_bat percentage
if has "pmset"; then
current_bat="$(pmset -g ps | grep -o '[0-9]\+%' | tr -d '%')"
elif has "ioreg"; then
local _battery_info _max_cap _cur_cap
_battery_info="$(ioreg -n AppleSmartBattery)"
_max_cap="$(echo "$_battery_info" | awk '/MaxCapacity/{print $5}')"
_cur_cap="$(echo "$_battery_info" | awk '/CurrentCapacity/{print $5}')"
current_bat="$(awk -v cur="$_cur_cap" -v max="$_max_cap" 'BEGIN{ printf("%.2f\n", cur/max*100) }')"
fi
# trim dot (e.g., 79.61 -> 79)
percentage="${current_bat%%.*}"
if [ -n "$percentage" ]; then
echo "$percentage%"
fi
}
# is_charging returns true if the battery is charging
is_charging() {
if has "pmset"; then
pmset -g ps | grep -E "Battery Power|charged" >/dev/null 2>&1
if [ $? -eq 0 ]; then
return 1
else
return 0
fi
elif has "ioreg"; then
ioreg -c AppleSmartBattery | grep "IsCharging" | grep "Yes" >/dev/null 2>&1
return $?
else
return 1
fi
}
# battery_color_ansi colourizes the battery level for the terminal
battery_color_ansi() {
local percentage
percentage="${1:-$(get_battery)}"
if is_charging; then
[[ -n $percentage ]] && echo -e "\033[32m${percentage}\033[0m"
else
# percentage > BATTERY_DANGER
if [ "${percentage%%%*}" -ge "$BATTERY_DANGER" ]; then
echo -e "\033[34m${percentage}\033[0m"
else
echo -e "\033[31m${percentage}\033[0m"
fi
fi
}
# battery_color_tmux colourizes the battery level for tmux
battery_color_tmux() {
local percentage
percentage="${1:-$(get_battery)}"
if is_charging; then
[[ -n $percentage ]] && echo -e "#[fg=colour46]${percentage}#[default]"
else
# percentage > BATTERY_DANGER
if [ "${percentage%%%*}" -ge "$BATTERY_DANGER" ]; then
echo -e "#[fg=blue]${percentage}#[default]"
else
echo -e "#[fg=red]${percentage}#[default]"
fi
fi
}
get_remain() {
local time_remain
if has "pmset"; then
time_remain="$(pmset -g ps | grep -o '[0-9]\+:[0-9]\+')"
if [ -z "$time_remain" ]; then
time_remain="no estimate"
fi
elif has "ioreg"; then
local itte
itte="$(ioreg -n AppleSmartBattery | awk '/InstantTimeToEmpty/{print $5}')"
time_remain="$(awk -v remain="$itte" 'BEGIN{ printf("%dh%dm\n", remain/60, remain%60) }')"
if [ -z "$time_remain" ] || [ "${time_remain%%h*}" -gt 10 ]; then
time_remain="no estimate"
fi
else
time_remain="no estimate"
fi
echo "$time_remain"
if [ "$time_remain" = "no estimate" ]; then
return 1
fi
}
# this scripts is supported OS X only now
# if ! is_osx; then
# echo "OS X only" 1>&2
# exit 1
# fi
# check arguments
for i in "$@"
do
case "$i" in
"-h"|"--help")
echo "usage: battery [--help|-h][--ansi|--tmux][-r|--remain]" 1>&2
echo " Getting the remaining battery, then" 1>&2
echo " outputs and colourizes with options" 1>&2
exit
;;
"--ansi")
battery_color_ansi "$(get_battery)"
exit $?
;;
"--tmux")
battery_color_tmux "$(get_battery)"
exit $?
;;
"-r"|"--remain")
get_remain
exit $?
;;
-*|--*)
echo "$i: unknown option" 1>&2
exit 1
esac
done
get_battery
#!/bin/bash
echo $(dig +short myip.opendns.com @resolver1.opendns.com)
#!/bin/bash
echo -e $(tmux list-panes | wc -l | sed "s/ //g")
#!/bin/bash
#
# @(#) wifi v0.2.0 2015-09-24
#
# usage:
# wifi [-h|--help]
#
# description:
# show the wifi information (strength, bandwidth, SSID)
#
######################################################################
# Use: Put something this in your .tmux.conf file
# set-option -g status-right: '#(wifi -c tmux)'
#
# ▁▂▃▅▇
# . "$DOTPATH"/etc/lib/vital.sh
# if ! is_osx; then
# echo "wifi: require OS X" 1>&2
# exit 1
# fi
# Check arguments
# for arg in "$@"
# do
# # Check if arguments have help option
# if [[ "$arg" =~ ^"-h"|"--help"$ ]]; then
# cat 1>&2 <<-'EOH'
# usage: wifi [-h|--help]
# show the wifi information (strength, bandwidth, SSID)
# EOH
# exit 1
# fi
# done
# airport command is executable file
#
# Usage:
# Search information about Wi-Fi by using airport command
# airport command has this options
# -c[<arg>] --channel=[<arg>] Set arbitrary channel on the card
# -z --disassociate Disassociate from any network
# -I --getinfo Print current wireless status, e.g. signal info, BSSID, port type etc.
# -s[<arg>] --scan=[<arg>] Perform a wireless broadcast scan.
# Will perform a directed scan if the optional <arg> is provided
# -x --xml Print info as XML
# -P --psk Create PSK from specified pass phrase and SSID.
# The following additional arguments must be specified with this command:
# --password=<arg> Specify a WPA password
# --ssid=<arg> Specify SSID when creating a PSK
# -h --help Show this help
#
airport_path="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
# Check if airport is available
if [[ ! -x $airport_path ]]; then
echo "$airport_path: not found" 1>&2
exit 1
fi
# The Unicode Block Elements
# | Unicode | Block | Name | Note |
# |:-------:|:-----:|:--------------------------:|:----------:|
# | 2580 | ▀ | UPPER HALF BLOCK | |
# | 2581 | ▁ | LOWER ONE EIGHTH BLOCK | |
# | 2582 | ▂ | LOWER ONE QUARTER BLOCK | |
# | 2583 | ▃ | LOWER THREE EIGHTHS BLOCK | |
# | 2584 | ▄ | LOWER HALF BLOCK | |
# | 2585 | ▅ | LOWER FIVE EIGHTHS BLOCK | |
# | 2586 | ▆ | LOWER THREE QUARTERS BLOCK | |
# | 2587 | ▇ | LOWER SEVEN EIGHTHS BLOCK | |
# | 2588 | █ | FULL BLOCK | →25A0(■) |
# | 2589 | ▉ | LEFT SEVEN EIGHTHS BLOCK | |
# | 258A | ▊ | LEFT THREE QUARTERS BLOCK | |
# | 258B | ▋ | LEFT FIVE EIGHTHS BLOCK | |
# | 258C | ▌ | LEFT HALF BLOCK | |
# | 258D | ▍ | LEFT THREE EIGHTHS BLOCK | |
# | 258E | ▎ | LEFT ONE QUARTER BLOCK | |
# | 258F | ▏ | LEFT ONE EIGHTH BLOCK | |
# | 2590 | ▐ | RIGHT HALF BLOCK | |
#
# signals=(▂▅▇)
signals=()
# Get the wifi information and then set it to an info array
info=( $(eval "$airport_path" --getinfo | grep -E "^ *(agrCtlRSSI|state|lastTxRate|SSID):" | awk '{print $2}') )
if [[ ${#info[@]} -eq 0 ]]; then
echo "offline"
exit 1
fi
# cut out a needed information from the info
# reference: http://osxdaily.com/2007/01/18/airport-the-little-known-command-line-wireless-utility/
rssi="${info[0]}" # strength of wifi wave
stat="${info[1]}" # whether wifi is available
rate="${info[2]}" # bandwidth of wifi wave
ssid="${info[3]}" # wifi ssid name
# Determine the signal from rssi of wifi
signal=""
for ((j = 0; j < "${#signals[@]}"; j++))
do
# reference of strength (rssi)
# -20 Excellent
# -30 Excellent
# -40 Excellent
# -50 Excellent
# -60 better
# -70 good
# -80 not good
# -90 bad
# -100 bad
if (( $j == 0 && $rssi > -100 )) ||
(( $j == 1 && $rssi > -80 )) ||
(( $j == 2 && $rssi > -50 )); then
# make signal
signal="${signal}${signals[$j]} "
else
signal="${signal} "
fi
done
# If the wifi rate (wifi bandwidth) is unavailable,
if [ "$rate" = 0 ]; then
echo "no_wifi"
exit 1
fi
# Outputs wifi
# example: "fun-wifi 351Mbs ▂ ▅ "
echo -e "${ssid}"
# echo -e "${ssid} ${rate}Mbs"
# echo -e "${ssid} ${rate}Mbs ${signal}"
# echo -e "${ssid} ${signal}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment