Skip to content

Commit

Permalink
Add fisher v4 support (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
0rax authored Mar 4, 2022
2 parents 17f52b6 + 3560cc0 commit 4b611b7
Show file tree
Hide file tree
Showing 42 changed files with 82 additions and 60 deletions.
2 changes: 1 addition & 1 deletion internals/README.md → DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Internals
# Documentation

## Internal functions

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ end
### Using [Fisher](https://github.com/jorgebucaran/fisher)
This is the easiest way to install `fishline` in your fish-shell environment. Fisherman will install it and link all the needed functions for you by running the following command:
This is the easiest way to install `fishline` in your fish-shell environment. Fisher will install it and link all the needed functions for you by running the following command:
```sh
fisher add 0rax/fishline
fisher install 0rax/fishline
```
This will allow you to use the `fishline` command directly and access to all the possible theming / configuration available as if you installed it manually.
> **NOTE**:
> When installing fishline using Fisher, a file named `fishline-init.fish` will be created in `~/.config/fish/conf.d`.
> If you wish to configure, you should not update this file but instead create a new one to set your configuration variable, just make sure that this file is loaded after it (naming the file `fishline.fish` or `fishline-theme.fish` should work).
## Configuration
To use fishline as your prompt, update or create a `fish_prompt.fish` file in your `functions` folder (`~/.config/fish/functions` by default) to include:
Expand Down
8 changes: 8 additions & 0 deletions completions/fishline.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
complete -c fishline --no-files
complete -c fishline -a "(fishline -x)"
complete -c fishline -x -n __fish_use_subcommand -s s -d "Set the last command status exit code"
complete -c fishline -n __fish_use_subcommand -s l -d "Generate a fish_prompt"
complete -c fishline -n __fish_use_subcommand -s r -d "Generate a fish_right_prompt"
complete -c fishline -x -n __fish_use_subcommand -s x -d "Print the list of availlable segment and exit"
complete -c fishline -x -n __fish_use_subcommand -s v -d "Print the software version and exit"
complete -c fishline -x -n __fish_use_subcommand -s h -d "Print help message"
34 changes: 34 additions & 0 deletions conf.d/fishline-init.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-

if not set -q FLINE_THEME_DIR
if type -q realpath
set FLINE_THEME_DIR (dirname (realpath (status -f)))/fishline-themes
else
set FLINE_THEME_DIR (dirname (status -f))/fishline-themes
end
end

# Load default symbols
source $FLINE_THEME_DIR/default_symbols.fish

# Load default color theme depending on terminal capabilities
if begin; [ (uname) != "Darwin" ]; and tty | grep tty > /dev/null; end
# Emable a TTY safe default theme if a TTY is detected
source $FLINE_THEME_DIR/tty_compatible.fish
else if begin; not command -s tput > /dev/null; or [ (tput colors) -lt 256 ]; end
# Assume ANSI 8 Colors when tput is not availlable & tput colors < 256
source $FLINE_THEME_DIR/default_ansi_colors.fish
else
# Load default 256 colors theme otherwise
source $FLINE_THEME_DIR/default_256_colors.fish
end

# Default Fishline Prompt
set FLINE_DEFAULT_PROMPT vimode sigstatus jobs pwd git write n root

# Set Signal Code list for internal use
set FLSEG_STATUS_NAME (command kill -l| tr ' [a-z]' '\n[A-Z]')

# Set internal initialization flag
set _fishline_init true
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-

set __256_blue 08f
set __256_red d00
set __256_grey 4e4e4e
set __256_green 5d5
set __256_yellow fd0
set __256_purple 868
set __256_cyan 688
set __256_white eee
set -l __256_blue 08f
set -l __256_red d00
set -l __256_grey 4e4e4e
set -l __256_green 5d5
set -l __256_yellow fd0
set -l __256_purple 868
set -l __256_cyan 688
set -l __256_white eee

# Color for PWD and FULLPWD segment
set FLCLR_PWD_BG_HOME $__256_blue
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Argument and Options:
-s \$num Set the last command status exit code (should be internal \$status)
This is only used by a limited number of segment but it should be
set everytime you call fishline (if not needed set it to 0)
-l left mode: generate a fish_prompt compatible prompt (default)
-r right mode: generate a fish_right_prompt compatible prompt
-l Left mode: generate a fish_prompt compatible prompt (default)
-r Right mode: generate a fish_right_prompt compatible prompt
-x Print the list of availlable segment and exit
-h Print this help and exit
-v Print the software version and exit
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function __flseg_vfish

if set -q VIRTUAL_ENV
__fishline_segment $FLCLR_VFISH_BG $FLCLR_VFISH_FG
printf "$FLSYM_VFISH"(basename $VIRTUAL_ENV)
printf "$FLSYM_VFISH%s" (basename $VIRTUAL_ENV)
end

end
File renamed without changes.
File renamed without changes.
50 changes: 11 additions & 39 deletions init.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,17 @@
# -*- mode:fish; tab-width:4 -*-

# If FLINE_PATH is not set, trying to find it from init.fish path
if test -z "$FLINE_PATH"
if type -q realpath
set -gx FLINE_PATH (dirname (realpath (status -f)))
else
set -gx FLINE_PATH (dirname (status -f))
end
if not set -q FLINE_PATH
if type -q realpath
set -gx FLINE_PATH (dirname (realpath (status -f)))
else
set -gx FLINE_PATH (dirname (status -f))
end
set FLINE_THEME_DIR $FLINE_PATH/themes
end

if not set -q FLINE_INIT
set -g FLINE_INIT true
# Use FLINE_PATH to load internals, functions and segments
if [ "$FLINE_PATH" = "$HOME/.config/fish/conf.d" -a -d "$HOME/.config/fisherman/fishline" ]
# Assumes fishline has been installed using fisherman on system without realpath
set -gx FLINE_PATH $HOME/.config/fisherman/fishline
set -ga fish_function_path $FLINE_PATH/internals $FLINE_PATH/segments
else
# Standard installation, add function loading path
set -ga fish_function_path $FLINE_PATH/functions $FLINE_PATH/internals $FLINE_PATH/segments
end
if not set -q fishline_init
set -a fish_function_path $FLINE_PATH/functions
set -a fish_completion_path $FLINE_PATH/completion.d
source $FLINE_PATH/conf.d/fishline-init.fish
end

# Load default color theme based on tput output
if begin; not command -s tput > /dev/null; or [ (tput colors) -lt 256 ]; end
# Assume ANSI 8 Colors when tput is not availlable & tput colors < 256
source $FLINE_PATH/themes/default_ansi_colors.fish
else
source $FLINE_PATH/themes/default_256_colors.fish
end

# Load default symbols
source $FLINE_PATH/themes/default_symbols.fish

# Set special themes based if on a tty or not
if begin; [ (uname) != "Darwin" ]; and tty | grep tty > /dev/null; end
source $FLINE_PATH/themes/tty_compatible.fish
end

# Default Fishline Prompt
set FLINE_DEFAULT_PROMPT vimode sigstatus jobs pwd git write n root

# Set Signal Code list for internal use
set FLSEG_STATUS_NAME (command kill -l| tr ' [a-z]' '\n[A-Z]')
14 changes: 8 additions & 6 deletions tests/fltest_git.fish
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function fltest_git

set _OLDPWD $PWD

git clone https://github.com/0rax/fishline.git /tmp/fishline_test ^ /dev/null > /dev/null
git clone https://github.com/0rax/fishline.git /tmp/fishline_test 2> /dev/null
echo
echo

echo "Context: Not in a git repository"
cd /tmp
Expand All @@ -34,20 +36,20 @@ function fltest_git
touch test_fishline
git add test_fishline
__fishline_test GIT
git rm -rf test_fishline > /dev/null ^ /dev/null
git rm -rf test_fishline > /dev/null 2> /dev/null

git commit -am "Testing GIT Segment" --allow-empty > /dev/null ^ /dev/null
git commit -am "Testing GIT Segment" --allow-empty > /dev/null ^ /dev/null
git commit -am "Testing GIT Segment" --allow-empty > /dev/null 2> /dev/null
git commit -am "Testing GIT Segment" --allow-empty > /dev/null 2> /dev/null
echo "Context: with commits ahead and behind in branch dev"
git checkout -b dev > /dev/null ^ /dev/null
git checkout -b dev > /dev/null 2> /dev/null
__fishline_test GIT

echo "Context: EVERYTHING"
touch test_fishline_untracked
echo test_fishline >> LICENSE
touch test_fishline
git add test_fishline
git commit --allow-empty -m "Empty commit" > /dev/null ^ /dev/null
git commit --allow-empty -m "Empty commit" > /dev/null 2> /dev/null
__fishline_test GIT

rm -rf /tmp/fishline_test
Expand Down
3 changes: 2 additions & 1 deletion tests/run.fish
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ end

# Init fishline
set FLINE_PATH (git rev-parse --show-toplevel)
source $FLINE_PATH/init.fish
set -a fish_function_path $FLINE_PATH/functions
set -a fish_function_path $FLINE_PATH/tests
source $FLINE_PATH/conf.d/fishline-init.fish

# Get segment list to check
if [ "$all_seg" = "true" ]
Expand Down
1 change: 1 addition & 0 deletions themes

0 comments on commit 4b611b7

Please sign in to comment.