My .bash_aliases file contains several aliases. In the beginning, when I wanted to see the aliases, I print the .bash_aliases file,
The output wasn't readable at all, so I created a python script to make it better.
To call my python script, I use the alias print_aliases_manual
What is the most pythonic way to write the following script?
Here is my python script:
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
with open('/home/pi/.bash_aliases', 'r') as f:
lines = f.readlines()
for line in lines:
if r'##' in line:
print(f'{bcolors.HEADER}{bcolors.UNDERLINE}{bcolors.BOLD}{line}{bcolors.ENDC}')
elif r'#' in line:
print(f'{bcolors.WARNING}{line}{bcolors.ENDC}')
elif r'alias' in line:
drop_alias = line.replace('alias', '')
new_line = drop_alias.replace('=', ' ')
print(f'{bcolors.OKGREEN}{new_line}')
else:
print(f'{line}')
Here is my bash_aliases file:
### Aliases list divided by category:
## General commands:
alias cdd="cd /home/pi/Desktop/speedboat/"
alias dc="sudo docker-compose"
alias pm2="sudo pm2"
## Cellular related commands:
alias pc="ping -I wwan0 www.google.com"
alias qmi="sudo qmicli -d /dev/cdc-wdm0 -p"
## AWS relaeted commands:
alias dlogs="sudo docker logs -f iot_service"
## Git commands:
alias gp="sudo git pull"
alias gc="sudo git checkout"
## scripts to run when deleting speedboat directory is needed:
# copying files to Desktop
alias stodtop="sudo -E sh /home/pi/Desktop/speedboat/scripts/copy_files_to_desktop.sh"
# copying files from Desktop
alias sfromdtop="sudo -E sh /home/pi/Desktop/speedboat/scripts/copy_files_from_desktop_to_speedboat.sh"
## verifications test and updates scripts
# run speedboat verifications tests
alias sinsta="sudo sh /home/pi/Desktop/speedboat/scripts/installation_verification.sh"
# run local unittests
alias slocalt="sudo sh /home/pi/Desktop/speedboat/scripts/run_local_unittest.sh"
# pull os updates from git and execute
alias supdate="sudo sh /home/pi/Desktop/speedboat/scripts/updates-speedboat.sh"
## speedboat start and stop scripts (dockers and PM2)
alias startr="sudo sh /home/pi/Desktop/speedboat/scripts/start_speedboat.sh"
alias stopr="sudo sh /home/pi/Desktop/speedboat/scripts/stop_speedboat.sh"
## AWS related scripts:
alias secrl="sudo sh /home/pi/Desktop/speedboat/scripts/ecr-login.sh"
alias slog="sudo sh /home/pi/Desktop/speedboat/scripts/log_register.sh"
## Command to run speedboat aliases manual:
alias print_aliases_manual="python3 /home/pi/Desktop/speedboat/verification/test_verification_speedboat/colored_aliases_manual.py"