Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
O
oh-my-fish
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
oh-my-fish
Commits
f7e4df1e
Commit
f7e4df1e
authored
Jan 14, 2014
by
Bruno Pinto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #109 from syl20bnr/syl20bnr-theme
parents
4625caed
61c3a208
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
296 additions
and
0 deletions
+296
-0
themes/syl20bnr/README.md
themes/syl20bnr/README.md
+113
-0
themes/syl20bnr/fish_prompt.fish
themes/syl20bnr/fish_prompt.fish
+183
-0
No files found.
themes/syl20bnr/README.md
0 → 100644
View file @
f7e4df1e
# syl20bnr theme
Sylvain Benner personal, compact (hmmm...) yet complete (almost :-)) oh-my-fish theme.
**Table of Contents**
*generated with [DocToc](http://doctoc.herokuapp.com/)*
-
[
Segments
](
#segments
)
-
[
pwd: Compact current working directory
](
#pwd-compact-current-working-directory
)
-
[
Examples
](
#examples
)
-
[
git
](
#git
)
-
[
Examples
](
#examples-1
)
-
[
vi-mode
](
#vi-mode
)
-
[
end
](
#end
)
-
[
where
](
#where
)
-
[
Functions
](
#functions
)
-
[
Cygwin compatibility
](
#cygwin-compatibility
)
## Segments
### pwd: Compact current working directory
The
`pwd`
segment format is
`X:P(N)`
where:
-
`X`
is either
`home`
or
`/`
-
`P`
is the current working path base name (name of the current directory)
-
`N`
is the depth of the path starting from
`X`
If the
`pwd`
is
`home`
or
`/`
then the prompt format is simplified to
`home`
and
`/`
respectively without the current directory and depth.
#### Examples
In home directory:

Inside a directory in home:

Outside the home directory:

### git
If the current directory is a
[
git
][
git
]
repository then the
`pwd`
segment is
replaced by the
`git`
segment (I should know where I am).
The
`git`
segment format is
`X:YI@Z:P(N)`
where:
-
`X`
is
`git`
-
`Y`
is the current branch name
-
`I`
is the information about the current repository state
-
`Z`
is the name of the repository
-
`P`
is the current working path basename (name of the current directory)
If
`P`
=
`Z`
then
`P(N)`
is not displayed
-
`N`
is the depth of the path starting from base directory of the repository
The displayed information
`I`
is:
-
Dirtiness is indicated by a little dot after the branch name.
-
Unpushed commits are indicated with up arrows
-
The number of unpushed commits is indicated right after the up arrows
#### Examples
Dirty:

Unpushed commits:

In a sub-directory of the repository:

### vi-mode
This segment display the current
`vi-mode`
if the plugin is used.
See the
`[n]`
in the previous screenshots.
### end
The color of the end of the prompt depends on the
`$status`
value of the
last executed command. It is
`green`
or
`red`
depending on the success or
failure of the last command.
Since I often use
[
ranger
][
ranger
]
and its
`shift+s`
key binding to bring
a new child shell session, there is a discreet indicator when the parent
process of the current shell is a
`ranger`
process: the end of the prompt
is written twice (ie:
`>>`
instead of just
`>`
).
With this indicator I quickly see if I can
`ctrl+d`
to end the current shell
process and go back to the parent
`ranger`
process.
### where
The
`where`
segment format is
`X@Y`
where:
-
`X`
is the user name
-
`Y`
is the host name
This segment is displayed in the right prompt.
## Functions
Some functions come with the theme:
-
`toggle_right_prompt`
will... toggle the right prompt! (alias:
`trp`
)
## Cygwin compatibility
In order to make this theme work on
[
Cygwin
][
cygwin
]
, make sure to install the following
packages:
-
`bc`
for
`math`
fish function
-
`psmisc`
for
`pstree`
-
`git`
if you want to use the
`git`
segment.
[
git
]:
http://git-scm.com/
[
ranger
]:
http://ranger.nongnu.org/
[
cygwin
]:
http://cygwin.com/
themes/syl20bnr/fish_prompt.fish
0 → 100644
View file @
f7e4df1e
# name: syl20bnr
# ----------------------------------------------------------------------------
# Utils
# ----------------------------------------------------------------------------
set -g __syl20bnr_display_rprompt 1
function toggle_right_prompt -d "Toggle the right prompt of the syl20bnr theme"
if test $__syl20bnr_display_rprompt -eq 0
echo "enable right prompt"
set __syl20bnr_display_rprompt 1
else
echo "disable right prompt"
set __syl20bnr_display_rprompt 0
end
end
function __syl20bnr_git_branch_name -d "Return the current branch name"
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function __syl20bnr_git_repo_name -d "Return the current repository name"
echo (command basename (git rev-parse --show-toplevel ^/dev/null))
end
function __syl20bnr_git_repo_base -d "Return the current repository name"
echo (command git rev-parse --show-toplevel ^/dev/null)
end
function __syl20bnr_is_git_dirty -d "Check if there is uncommited changes"
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function __syl20bnr_is_git_ahead -d "Check if there is unpushed commits"
echo (command git status -s -b ^/dev/null | grep ahead)
end
function __syl20bnr_unpushed_commit_count -d "Return the number of unpushed commits"
git status -s -b ^/dev/null | grep -E -o "ahead\ [0-9]+" | awk '{print $2}'
end
# ----------------------------------------------------------------------------
# Aliases
# ----------------------------------------------------------------------------
alias trp toggle_right_prompt
# ----------------------------------------------------------------------------
# Prompts
# ----------------------------------------------------------------------------
function fish_prompt -d "Write out the left prompt of the syl20bnr theme"
set -l last_status $status
set -l basedir_name (basename (prompt_pwd))
# Init colors
set -l colcyan (set_color cyan)
set -l colbcyan (set_color -o cyan)
set -l colgreen (set_color green)
set -l colbgreen (set_color -o green)
set -l colnormal (set_color normal)
set -l colred (set_color red)
set -l colbred (set_color -o red)
set -l colwhite (set_color white)
set -l colbwhite (set_color -o white)
# Segments
# git
# If inside a git repo then the pwd segment is replaced by the git
# segment.
# The git segment format is X:YI@Z:P(N) where:
# X is git
# Y is the current branch
# I is the information about the current repo state
# Z is the name of the repo
# P is the current working path basename (name of the current directory)
# C is the depth of the path starting from base directory of the repo
# The displayed information is:
# Dirtiness is indicated by a little dot after the branch name.
# Unpushed commits are indicated with up arrows
# The number of unpushed commits is indicated right after the up arrows
# If P = Z then P(C) is not displayed
set -l ps_git ""
set -l git_branch_name (__syl20bnr_git_branch_name)
if test -n "$git_branch_name"
set -l git_repo_name (__syl20bnr_git_repo_name)
set -l git_info ""
if test -n (__syl20bnr_is_git_ahead)
set git_info $colbgreen"↑↑↑"$colnormal"("(__syl20bnr_unpushed_commit_count)")"
end
if test -n (__syl20bnr_is_git_dirty)
set git_info $git_info$colbred"·"
end
set ps_git $colbwhite"git:"$colbcyan$git_branch_name$git_info$colnormal"@"$colbred$git_repo_name
if test "$basedir_name" != "$git_repo_name"
set -l basedir_depth (echo (__syl20bnr_git_repo_base) | cut -d "/" --output-delimiter=" " -f 1- | wc -w)
set -l depth (echo (pwd) | cut -d "/" --output-delimiter=" " -f 1- | wc -w)
set depth (math $depth - $basedir_depth)
set ps_git $ps_git$colbwhite":"$colbgreen$basedir_name$colnormal"("$depth")"
end
end
# pwd
# The pwd segment format is X:P(C) where:
# X is either home or /
# P is the current working path basename (name of the current directory)
# C is the depth of the path starting from X
# If the pwd is home or / then the prompt format is simplified to 'home' or
# '/' without the current directory and depth.
set -l ps_pwd ""
if test -z "$ps_git"
set -l depth (echo (pwd) | cut -d "/" --output-delimiter=" " -f 1- | wc -w)
set -l in_home (echo (pwd) | grep ~)
if test -n "$in_home"
set ps_pwd $colbwhite"home"
else
set ps_pwd $colbwhite"/"
end
if test (echo (pwd)) != ~ -a (echo (pwd)) != /
set ps_pwd $ps_pwd":"$colgreen$basedir_name
if test -n "$in_home"
set depth (math $depth - 2)
end
set ps_pwd $ps_pwd$colnormal"("$depth")"
end
end
# vi mode
# If vi_mode plugin is activated then print the vi mode in the prompt.
set -l ps_vi ""
if test -n "$vi_mode"
set ps_vi $colnormal"["$vi_mode$colnormal"]"
end
# end of prompt
# The color of the end of the prompt depends on the $status value of the
# last executed command. It is green or red depending on the last command
# success or failure respectively.
# Since I often use ranger and use its 'shift+s' key binding to bring a shell
# session, there is discreet indicator when the parent process of the current
# shell pid is a ranger process. In this case the end of the prompt is written
# twice.
# With this indicator I can quickly remember that I can "ctrl+d" to end the
# the current shell process and get back to the ranger process.
set -l ps_end ">"
# indicator for ranger parent process
set ranger ""
if pstree -p -l | grep "fish("(echo %self)")" | grep 'ranger([0-9]*)' > /dev/null
set ps_end $ps_end$ps_end
end
# last status give the color of the right arrows at the end of the prompt
if test $last_status -ne 0
set ps_end $colnormal$colbred$ps_end
else
set ps_end $colnormal$colgreen$ps_end
end
# Left Prompt
echo -n -s $ps_git $ps_pwd $ps_vi $ps_git_dirty $ps_end ' '
end
function fish_right_prompt -d "Write out the right prompt of the syl20bnr theme"
set -l colnormal (set_color normal)
# Segments
# The where segment format is X@Y where:
# X is the username
# Y is the hostname
set -l ps_where $colnormal(whoami)@(hostname|cut -d . -f 1)
# Right Prompt
if test $__syl20bnr_display_rprompt -eq 1
echo -n -s $ps_where
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment