Last active
February 22, 2024 06:18
-
-
Save leiless/3b4d8160c4a06ce6340b03ac1ab827db to your computer and use it in GitHub Desktop.
Bring bash's pushd/popd to Python3
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
#!/usr/bin/env python3 | |
import os | |
import sys | |
DIR_STACK = [] | |
def pushd(path: str): | |
DIR_STACK.append(os.getcwd()) | |
os.chdir(path) | |
def popd(): | |
os.chdir(DIR_STACK.pop()) | |
if __name__ == '__main__': | |
pushd(os.path.dirname(os.path.realpath(sys.argv[0]))) | |
# main() | |
popd() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment