Skip to content

Instantly share code, notes, and snippets.

@mrozo
Created May 9, 2019 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrozo/defcf3ac8af271038c8861fd8d0ff02c to your computer and use it in GitHub Desktop.
Save mrozo/defcf3ac8af271038c8861fd8d0ff02c to your computer and use it in GitHub Desktop.
Welcome screen for tmux with calendar, tmux help and disk free space
#!/bin/env/python3
import calendar
import time
from subprocess import check_output
import os
DISKS = (' /home',' /', ' /home/windows', ' /media/backup')
TMUX_CHEATSHEET = """ │
Sessions │ Panes (splits)
:new<CR> new session │ % vertical split
s list sessions │ " horizontal split
$ name session │ o swap panes
Windows (tabs) │ q show pane numbers
c create window │ x kill pane
w list windows │ + break pane into window (e.g. to select text by
n next window │ mouse to copy)
p previous window │ - restore pane from window
f find window │ ⍽ space - toggle between layouts
, name window │ q (Show pane numbers, when the numbers show up
& kill window │ type the key to goto that pane)
│ { (Move the current pane left)
│ } (Move the current pane right)
│ z toggle pane zoom
│"""
rows, columns = os.popen('stty size', 'r').read().split()
rows = int(rows)
columns = int(columns)
def print_calendar():
month=int(time.strftime("%m"))
year=int(time.strftime("%y"))
current = calendar.month(year,month)
prev_month=month-1 if month > 2 else 12
prev_year=year if prev_month != 12 else year-1
next_month=((month)%12)+1
next_year=year if next_month!= 1 else year+1
today=time.strftime(u" %e ")
today_marked = time.strftime(
u"\033[7m\033[7;30;46m\033[0m\033[1;30;46m%e\033[7m\033[1;30;46m\033[0m"
)
current = current.replace(today, today_marked).split('\n')
previous = calendar.month(prev_year, prev_month).split('\n')
next = calendar.month(next_year, next_month).split('\n')
parts = [previous, current, next]
line_len = max(map(lambda line:len(line), next))
parts = map(lambda part:map(lambda line_part: line_part.ljust(line_len,' '),part), parts)
return ('\n'.join(map(lambda p,c,n: ' '*(int((80-((3*line_len)+14))/2)) + (' │ '.join([p,c,n])), *parts)))
def print_disks_report():
out_str = ''
disks = filter(
lambda line: line.endswith(DISKS),
check_output(['df','-h']).decode("UTF-8").split('\n')
)
disks = map(lambda line: line.split(' '), disks)
disks = map(lambda line: filter(lambda part: part!='', line), disks)
for line in disks:
line=list(line)
out_line=''
if int(line[-2].split('%')[0]) > 80:
out_line = "\033[4;37;41m"
out_line += line[-1].ljust(20) + line[-2].rjust(3)
out_line += "\033[0m"
out_line = out_line.strip()
out_line = str(' '*int((80-len(out_line))/2)) + out_line
out_str += out_line +'\n'
return out_str
def center_align(str_in):
left_margin = int((columns-80)/2)
lines = str_in.splitlines()
height = len(lines)
vertical_margin = int((rows-height)/2)
return str('\n'*vertical_margin) + \
'\n'.join(map(lambda line: (' '*left_margin) + line, lines)) +\
str('\n'*(vertical_margin-1))
def hr():
return '\n' + str('─'*80) + '\n'
print(center_align(print_calendar() + hr()\
+TMUX_CHEATSHEET+ hr()\
+print_disks_report()))
@leszekbulawa
Copy link

Whoa this is cool m8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment