Skip to content

Instantly share code, notes, and snippets.

@SpotlightKid
Created November 21, 2017 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpotlightKid/06cfc16b583422d764a4d1c03b310028 to your computer and use it in GitHub Desktop.
Save SpotlightKid/06cfc16b583422d764a4d1c03b310028 to your computer and use it in GitHub Desktop.
Get a list of BASH alias definitions (requires Python 3.5+)
from subprocess import PIPE, run, STDOUT
def get_aliases():
aliases = []
for line in run(["bash", '-i'], input='alias', stdout=PIPE, stderr=PIPE,
env={'PS1': ''}, encoding='utf-8').stdout.splitlines():
name, cmd = line.split('=', 1)
aliases.append((name[6:], cmd[1:-1]))
return aliases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment