Skip to content

Instantly share code, notes, and snippets.

@muffinresearch
Last active August 29, 2015 14:05
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 muffinresearch/255def06571d8e797f36 to your computer and use it in GitHub Desktop.
Save muffinresearch/255def06571d8e797f36 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple command that prints out the current n last levels of the CWD
replacing the prefix with a horizontal ellipsis
Usage pwdn [numdirs]
"""
from os import getcwd
from sys import argv, exit
try:
numdir = (len(argv) > 1) and int(argv[1]) or 2
except ValueError:
print "Usage: pwdn [numdirs]"
exit(1)
cwd = getcwd()[1:].split("/")
print "%s%s" % (len(cwd) > numdir and "…/" or "/", '/'.join(cwd[-numdir:]))
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment