Skip to content

Instantly share code, notes, and snippets.

@elreydetoda
Created July 23, 2021 13:35
Show Gist options
  • Save elreydetoda/e795b81e96a7477aa6cb9abb155c452a to your computer and use it in GitHub Desktop.
Save elreydetoda/e795b81e96a7477aa6cb9abb155c452a to your computer and use it in GitHub Desktop.
inspired by Julia Evans' (https://twitter.com/b0rk) header script from https://youtu.be/mFKrw_zTbpc ( https://changelog.fm/450 )
#!/usr/bin/env python3
# inspired by Julia Evans' (https://twitter.com/b0rk) header script from
# https://changelog.fm/450 ( https://youtu.be/mFKrw_zTbpc )
import fileinput
# takes stdin from visual mode of vim and ! to execute this script
lines = [ x.strip().rstrip(' #').lstrip('# ') for x in fileinput.input() ]
# getting the longest line length from the input
line_len = max(len(line) for line in lines)
# padding for 2 on either side
total_len = line_len + 4
# print starter of all #
print('#' * total_len )
# add # to beginning and end of lines
for line in lines:
# skip output if line is empty
if len(line) == 0:
continue
print('# ', end='')
print(line, end='')
print(' ' * (line_len - len(line)), end='')
print(' #')
# print final of all #
print('#' * total_len)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment