prompt: remove git blacklist, use timeout instead
This commit is contained in:
parent
6691f43ab6
commit
4850e142aa
1 changed files with 20 additions and 23 deletions
|
@ -47,8 +47,6 @@ COLOR_ERROR = 196
|
||||||
MOUNT_IGNORE_FS = ["iso9660", "tmpfs", "rootfs"]
|
MOUNT_IGNORE_FS = ["iso9660", "tmpfs", "rootfs"]
|
||||||
MOUNT_IGNORE_DIR = ["/dev", "/proc", "/sys"]
|
MOUNT_IGNORE_DIR = ["/dev", "/proc", "/sys"]
|
||||||
|
|
||||||
GIT_BLACKLIST = ["/var/paludis/repositories"]
|
|
||||||
|
|
||||||
def get_username():
|
def get_username():
|
||||||
return pwd.getpwuid(os.geteuid())[0]
|
return pwd.getpwuid(os.geteuid())[0]
|
||||||
|
|
||||||
|
@ -321,7 +319,7 @@ class PathPart(Part):
|
||||||
|
|
||||||
self.fragments.append(str(dir))
|
self.fragments.append(str(dir))
|
||||||
|
|
||||||
def command(cmd):
|
def command(cmd, timeout=0.5):
|
||||||
"""
|
"""
|
||||||
Executes a command, returns stdout, suppresses stderr."
|
Executes a command, returns stdout, suppresses stderr."
|
||||||
"""
|
"""
|
||||||
|
@ -330,7 +328,7 @@ def command(cmd):
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
|
|
||||||
s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
s.wait()
|
s.wait(timeout)
|
||||||
|
|
||||||
return s.stdout.read().decode("utf-8")
|
return s.stdout.read().decode("utf-8")
|
||||||
|
|
||||||
|
@ -414,13 +412,13 @@ class WineprefixPart(Part):
|
||||||
|
|
||||||
class GitPart(Part):
|
class GitPart(Part):
|
||||||
"""
|
"""
|
||||||
↘2 ↗4 ⚠master ?11 ✎6 ✉10
|
↘2 ↗4 ⚠M master ?11 ✎6 ✉10
|
||||||
|
|
||||||
- 2 commits are available for pulling (remote is ahead)
|
- 2 commits are available for pulling (remote is ahead)
|
||||||
- 4 commits are available for pushing (local is ahead)
|
- 4 commits are available for pushing (local is ahead)
|
||||||
- we're merging
|
- we're merging
|
||||||
- branch name is master
|
- branch name is master
|
||||||
- 11 untracked filed
|
- 11 untracked files
|
||||||
- 6 modified files
|
- 6 modified files
|
||||||
- 10 modified and staged files
|
- 10 modified and staged files
|
||||||
|
|
||||||
|
@ -430,22 +428,17 @@ class GitPart(Part):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Part.__init__(self)
|
Part.__init__(self)
|
||||||
|
|
||||||
# avoid expensive parsing if blacklisted
|
|
||||||
cwd = os.getcwd()
|
|
||||||
deep_parse = not any([cwd.startswith(d) for d in GIT_BLACKLIST])
|
|
||||||
|
|
||||||
branch_name = command("git name-rev --name-only --no-undefined --always HEAD").strip()
|
branch_name = command("git name-rev --name-only --no-undefined --always HEAD").strip()
|
||||||
#branch_name = command("git symbolic-ref HEAD").strip()#.remove("refs/heads/")
|
|
||||||
|
|
||||||
if branch_name:
|
if branch_name:
|
||||||
self.fragments.append("↱ ")
|
try:
|
||||||
|
self.fragments.append("↱ ")
|
||||||
|
|
||||||
if deep_parse:
|
|
||||||
count_to_pull = command("git log --oneline ..@{u}").count("\n")
|
count_to_pull = command("git log --oneline ..@{u}").count("\n")
|
||||||
count_to_push = command("git log --oneline @{u}..").count("\n")
|
count_to_push = command("git log --oneline @{u}..").count("\n")
|
||||||
git_dir = command("git rev-parse --git-dir").strip()
|
git_dir = command("git rev-parse --git-dir").strip()
|
||||||
merging = os.path.exists(os.path.join(git_dir, "MERGE_HEAD"))
|
merging = os.path.exists(os.path.join(git_dir, "MERGE_HEAD"))
|
||||||
untracked = command("git ls-files --other --exclude-standard").count("\n")
|
untracked = command("git ls-files --other --exclude-standard", timeout=0.2).count("\n")
|
||||||
modified = command("git diff --name-only").count("\n")
|
modified = command("git diff --name-only").count("\n")
|
||||||
staged = command("git diff --name-only --staged").count("\n")
|
staged = command("git diff --name-only --staged").count("\n")
|
||||||
|
|
||||||
|
@ -458,16 +451,15 @@ class GitPart(Part):
|
||||||
if merging:
|
if merging:
|
||||||
self.fragments.append(style_color(COLOR_GIT_MERGE))
|
self.fragments.append(style_color(COLOR_GIT_MERGE))
|
||||||
self.fragments.append(style_bold())
|
self.fragments.append(style_bold())
|
||||||
self.fragments.append("⚠")
|
self.fragments.append("⚠M ")
|
||||||
elif modified or staged:
|
elif modified or staged:
|
||||||
self.fragments.append(style_color(COLOR_GIT_DIRTY))
|
self.fragments.append(style_color(COLOR_GIT_DIRTY))
|
||||||
else:
|
else:
|
||||||
self.fragments.append(style_color(COLOR_GIT_CLEAN))
|
self.fragments.append(style_color(COLOR_GIT_CLEAN))
|
||||||
|
|
||||||
self.fragments.append(branch_name)
|
self.fragments.append(branch_name)
|
||||||
self.fragments.append(style_reset())
|
self.fragments.append(style_reset())
|
||||||
|
|
||||||
if deep_parse:
|
|
||||||
if untracked:
|
if untracked:
|
||||||
self.fragments.append(style_color(COLOR_GIT_UNTRACKED))
|
self.fragments.append(style_color(COLOR_GIT_UNTRACKED))
|
||||||
self.fragments.append(" ?%d" %(untracked))
|
self.fragments.append(" ?%d" %(untracked))
|
||||||
|
@ -480,7 +472,12 @@ class GitPart(Part):
|
||||||
self.fragments.append(style_color(COLOR_GIT_STAGED))
|
self.fragments.append(style_color(COLOR_GIT_STAGED))
|
||||||
self.fragments.append(" ✉%d" %(staged))
|
self.fragments.append(" ✉%d" %(staged))
|
||||||
|
|
||||||
self.fragments.append(style_reset())
|
self.fragments.append(style_reset())
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
self.fragments = []
|
||||||
|
self.fragments.append(style_color(COLOR_GIT_DIRTY))
|
||||||
|
self.fragments.append("⚠ git timeout ⚠")
|
||||||
|
self.fragments.append(style_reset())
|
||||||
|
|
||||||
class Padding(Part):
|
class Padding(Part):
|
||||||
def __init__(self, term_width):
|
def __init__(self, term_width):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue