Skip to content

Instantly share code, notes, and snippets.

@xiaq
Last active July 7, 2017 16:05
Show Gist options
  • Select an option

  • Save xiaq/f5ed2c0fe5292c3d1bc1b93e5c612f3b to your computer and use it in GitHub Desktop.

Select an option

Save xiaq/f5ed2c0fe5292c3d1bc1b93e5c612f3b to your computer and use it in GitHub Desktop.
symbol-for=[&ahead="↑" &behind="↓" &diverged="⥄ " &dirty="⨯" &none="◦"]
fn ok [f]{
try $f
except; false
tried
}
fn not-ok [f]{
try $f; false
except
tried
}
fn is-repo {
if ok { test -d .git }; then
else ok { git rev-parse --dir >/dev/null 2>&1 }
fi
}
fn is-touched {
not-ok { git diff --no-ext-diff --quiet --exit-code }
}
fn branch-name {
try
git symbolic-ref --short HEAD
except
git show-ref --head -s --abbrev | head -n1
tried
}
fn commit-count {
splits &sep="\t" (git rev-list --count --left-right "@{upstream}...HEAD")
}
fn ahead {
{commits-behind,commits-ahead}=(commit-count)
if == $commits-behind 0; then
if == $commits-ahead 0; then
put none
else
put ahead
fi
else
if == $commits-ahead 0; then
put behind
else
put diverged
fi
fi
}
fn prompt {
le:styled (tilde-abbr $pwd) 32
if is-repo; then
put ' on '; le:styled (branch-name) 33
if is-touched; then
put ' '$symbol-for[dirty]
else
put ' '$symbol-for[(ahead)]
fi
fi
put '❱ '
}
le:prompt={ prompt }
@tbayne

tbayne commented Jul 7, 2017

Copy link
Copy Markdown

Does this work with the current version of elvish?

When I attempt to use it I get a bunch of "must be lambda" messages for the "try" statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment