Created
November 21, 2017 02:32
-
-
Save SpotlightKid/06cfc16b583422d764a4d1c03b310028 to your computer and use it in GitHub Desktop.
Get a list of BASH alias definitions (requires Python 3.5+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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