fishline!

This commit is contained in:
Zoe 2022-04-22 16:15:09 +02:00
parent 32babacd09
commit da454a7247
46 changed files with 1507 additions and 6 deletions

View file

@ -0,0 +1,43 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __fishline_segment --argument-name bg_clr fg_clr pre post -d "open a new fishline segment"
if [ "$FLINT_INVERT" = "true" -a "$FLINT_POSITION" = "left" ]; or [ "$FLINT_INVERT" != "true" -a "$FLINT_POSITION" = "right" ]
if [ "$FLINT_FIRST" != true ]
[ "$FLINT_PRINT_POST" = true ]; and printf "$FLSYM_RIGHT_POST"
end
if [ "$FLINT_LAST" != true ]
set_color $bg_clr
printf "$FLSYM_RIGHT_OPEN"
set_color $fg_clr -b $bg_clr
[ "$pre" = false ]; or printf "$FLSYM_RIGHT_PRE"
else
set_color normal -b normal
end
else
if [ "$FLINT_FIRST" != true ]
[ "$FLINT_PRINT_POST" = true ]; and printf "$FLSYM_LEFT_POST"
set_color -b $bg_clr
set_color "$FLINT_BCOLOR"
printf $FLSYM_LEFT_CLOSE
set_color normal
end
set_color -b $bg_clr $fg_clr
if [ "$FLINT_LAST" != true ]
[ "$pre" = false ]; or printf "$FLSYM_LEFT_PRE"
end
end
set FLINT_BCOLOR $bg_clr
set FLINT_FIRST false
set FLINT_LAST false
set FLINT_INVERT false
[ "$post" = false ]; and set FLINT_PRINT_POST false; or set FLINT_PRINT_POST true
end

View file

@ -0,0 +1,12 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __fishline_segment_close -d "close the previous fishline segment"
if [ "$FLINT_FIRST" != "true" ]
set FLINT_LAST true
__fishline_segment normal normal
set FLINT_FIRST true
end
end

View file

@ -0,0 +1,25 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __fishline_test --argument-names segment -d 'test segments'
set -g FLINT_TEST_SEG $segment
if not set -q FLINT_TEST_STATUS
set -g FLINT_TEST_STATUS 0
end
function flint_test_right
fishline -r -s $FLINT_TEST_STATUS $FLINT_TEST_SEG
end
function flint_test_left
fishline -l -s $FLINT_TEST_STATUS $FLINT_TEST_SEG
end
read -R flint_test_right -p flint_test_left TEST_VAR
set -e FLINT_TEST_VAR
set -e FLINT_TEST_SEG
set -e FLINT_TEST_STATUS
end

View file

@ -0,0 +1,34 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __fishline_usage
printf "# %s (%s)\n" (fishline -v) "https://github.com/0rax/fishline"
printf "
Powerline prompt for Fish Shell in Fish Shell.
Usage:
fishline [OPTIONS] [-s \$status] [segment ...]
Examples:
# Generate a fish_prompt compatible prompt
fishline -s \$status $FLINT_DEFAULT_PROMPT
# Generate a fish_right_prompt compatible prompt
fishline -r -s 0 CLOCK
Argument and Options:
segment This argument should match the name of the segment you wish to print
in your prompt. To Make sure that this segment exist, you can list
them using `fishline -x`
-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
-x Print the list of availlable segment and exit
-h Print this help and exit
-v Print the software version and exit
"
end

View file

@ -0,0 +1,12 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __fishline_version
pushd $FLINE_PATH > /dev/null
set -l fline_version (git describe --tag)
popd > /dev/null
printf "fishline %s\n" $fline_version
end

View file

@ -0,0 +1,9 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_arrow
__fishline_segment $FLCLR_ARROW_BG $FLCLR_ARROW_FG
printf $FLSYM_ARROW
end

View file

@ -0,0 +1,9 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_clock
__fishline_segment $FLCLR_CLOCK_BG $FLCLR_CLOCK_FG
printf "%s" (date "+%H:%M")
end

View file

@ -0,0 +1,11 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_conda
if set -q CONDA_DEFAULT_ENV
__fishline_segment $FLCLR_CONDA_BG $FLCLR_CONDA_FG
printf "$FLSYM_CONDA"(basename $CONDA_DEFAULT_ENV)
end
end

View file

@ -0,0 +1,30 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_exectime
set -l duration "$CMD_DURATION"
if [ $duration -ge 100 ]
__fishline_segment $FLCLR_EXECTIME_BG $FLCLR_EXECTIME_FG
set -l ms (math "$duration%1000")
if [ $duration -gt 36000000 ]
set -l h (math --scale=0 "$duration/36000000")
set -l min (math --scale=0 "$duration/60000%60")
printf "%sh %sm" $h $min
else if [ $duration -gt 60000 ]
set -l min (math --scale=0 "$duration/60000")
set -l s (math --scale=0 "$duration/1000%60")
printf "%sm %ss" $min $s
else if [ $duration -gt 1000 ]
set -l s (math --scale=0 "$duration/1000")
printf "%ss %sms" $s $ms
else
printf "%sms" $ms
end
end
end

View file

@ -0,0 +1,33 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_fish
if [ "$FLSYM_LEFT_CLOSE" != "\uE0B0" -o "$FLSYM_RIGHT_OPEN" != "\uE0B2" ]
__fishline_segment $FLCLR_FISH_BG $FLCLR_FISH_FG
if [ "$FLINT_POSITION" = "right" ]
printf "$FLSYM_FISH_ASCII_RIGHT"
else
printf "$FLSYM_FISH_ASCII_LEFT"
end
else if [ "$FLINT_POSITION" = "right" ]
__fishline_segment $FLCLR_FISH normal false false
printf " "
__flseg_invert
__fishline_segment normal $FLCLR_FISH false false
__fishline_segment $FLCLR_FISH $FLCLR_FISH false false
else
__fishline_segment $FLCLR_FISH $FLCLR_FISH false false
__fishline_segment normal $FLCLR_FISH false false
__flseg_invert
__fishline_segment $FLCLR_FISH normal false false
printf " "
end
end

View file

@ -0,0 +1,9 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_fullpwd
__fishline_segment $FLCLR_FULLPWD_BG $FLCLR_FULLPWD_FG
printf $PWD | sed "s|^$HOME|~|" | tr -d '\n'
end

View file

@ -0,0 +1,69 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_git
if git rev-parse --git-dir >> /dev/null 2> /dev/null
set -l detached 0
set -l ahead 0
set -l behind 0
set -l branch (git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [ "$status" -ne 0 ] # Repository is empty
set branch (git status —porcelain -b | head -n1 | cut -d' ' -f 3-)
set detached 1
else if [ "$branch" = "HEAD" ] # Repository is detached on tags / commit
set branch (git describe --tags --exact-match 2> /dev/null; or git log --format=%h --abbrev-commit -1 2> /dev/null)
set detached 1
else if git rev-parse --verify --quiet origin/$branch 2> /dev/null >> /dev/null
set ahead (git rev-list origin/$branch..$branch | wc -l)
set behind (git rev-list $branch..origin/$branch | wc -l)
end
# http://git-scm.com/docs/git-status
set -l gitstatus (git status --porcelain 2> /dev/null | cut -c 1-2 | awk 'BEGIN {s=0; n=0; u=0; t=0}; /^[MARCDU].$/ {s=1}; /^.[MDAU]$/ {n=1}; /^\?\?$/ {u=1}; {t=s+n+u} END {printf("%s\n%d\n%d\n%d", t, s, n, u)}')
# bool gitstatus[1] any changes
# bool gitstatus[2] staged changes
# bool gitstatus[3] unstaged changes
# bool gitstatus[4] untracked files
if [ $detached -eq 1 ]
set state Detached
else if [ $gitstatus[1] -gt 0 ]
set state Dirty
else
set state Clean
end
switch $state
case Dirty
__fishline_segment $FLCLR_GIT_BG_DIRTY $FLCLR_GIT_FG_DIRTY
printf "$FLSYM_GIT_BRANCH"
case Detached
__fishline_segment $FLCLR_GIT_BG_DETACHED $FLCLR_GIT_FG_DETACHED
printf "$FLSYM_GIT_DETACHED"
case '*'
__fishline_segment $FLCLR_GIT_BG_CLEAN $FLCLR_GIT_FG_CLEAN
printf "$FLSYM_GIT_BRANCH"
end
printf "$branch"
if [ $ahead -gt 0 ]
printf " %d$FLSYM_GIT_AHEAD" $ahead
end
if [ $behind -gt 0 ]
printf " %d$FLSYM_GIT_BEHIND" $behind
end
if [ $gitstatus[4] -eq 1 ]
printf " $FLSYM_GIT_UNTRACKED"
else if [ $gitstatus[3] -eq 1 ]
printf " $FLSYM_GIT_UNSTAGED"
else if [ $gitstatus[2] -eq 1 ]
printf " $FLSYM_GIT_STAGED"
end
end
end

View file

@ -0,0 +1,8 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_invert
set FLINT_INVERT true
end

View file

@ -0,0 +1,11 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_jobs
if [ (jobs | wc -l) -gt 0 ]
__fishline_segment $FLCLR_JOBS_BG $FLCLR_JOBS_FG
printf $FLSYM_JOBS
end
end

10
functions/__flseg_n.fish Normal file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_n
__fishline_segment_close
tput el
printf \n
end

View file

@ -0,0 +1,35 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_pwd
set -l pwd (prompt_pwd | sed -E 's;/?([^/]+)/?;\1'\u1F';g' | tr \u1F '\n')
set -l it 1
set -l len (expr (count $pwd) - 1)
if [ "$pwd[1]" = "~" ]
__fishline_segment $FLCLR_PWD_BG_HOME $FLCLR_PWD_FG_HOME
printf "~"
set it 2
else if [ "$pwd[1]" = "/" ]
__fishline_segment $FLCLR_PWD_BG $FLCLR_PWD_FG
printf "/"
end
if [ $it -le $len ]
__fishline_segment $FLCLR_PWD_BG $FLCLR_PWD_FG
for f in $pwd[$it..$len]
set it (expr $it + 1)
if test $it -le $len
printf "$f$FLSYM_SEPARATOR"
else
printf "$f"
end
end
end
end

View file

@ -0,0 +1,14 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_root
if [ "$USER" = "root" ]
__fishline_segment $FLCLR_ROOT_BG_ROOT $FLCLR_ROOT_FG_ROOT
printf $FLSYM_ROOT_ROOT
else
__fishline_segment $FLCLR_ROOT_BG_USER $FLCLR_ROOT_FG_USER
printf $FLSYM_ROOT_USER
end
end

View file

@ -0,0 +1,11 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_screen
if set -q STY
__fishline_segment $FLCLR_SCREEN_BG $FLCLR_SCREEN_FG
printf "$FLSYM_SCREEN"(echo $STY | cut -d'.' -f2-)
end
end

View file

@ -0,0 +1,9 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_separator
__fishline_segment "$FLCLR_SEPARATOR_BG" "$FLCLR_SEPARATOR_FG" false false
printf "$FLSYM_SEPARATOR_SEG"
end

View file

@ -0,0 +1,20 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_sigstatus
if [ $FLINT_STATUS -gt 128 -a $FLINT_STATUS -lt 160 ]
__fishline_segment $FLCLR_STATUS_BG $FLCLR_STATUS_FG
printf "SIG%s" $FLSEG_STATUS_NAME[(math "$FLINT_STATUS" - 128)]
else if [ $FLINT_STATUS -eq 126 ]
__fishline_segment $FLCLR_STATUS_BG $FLCLR_STATUS_FG
printf "NOEXEC"
else if [ $FLINT_STATUS -eq 127 ]
__fishline_segment $FLCLR_STATUS_BG $FLCLR_STATUS_FG
printf "NFOUND"
else if [ $FLINT_STATUS -gt 0 ]
__fishline_segment $FLCLR_STATUS_BG $FLCLR_STATUS_FG
printf $FLINT_STATUS
end
end

View file

@ -0,0 +1,10 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_space
__fishline_segment_close
type -q tput; and tput el
printf " "
end

View file

@ -0,0 +1,11 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_status
if [ $FLINT_STATUS -gt 0 ]
__fishline_segment $FLCLR_STATUS_BG $FLCLR_STATUS_FG
printf $FLINT_STATUS
end
end

View file

@ -0,0 +1,9 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_user
__fishline_segment $FLCLR_USER_BG $FLCLR_USER_FG
printf $USER
end

View file

@ -0,0 +1,9 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_userhost
__fishline_segment $FLCLR_USERHOST_BG $FLCLR_USERHOST_FG
printf '%s@%s' $USER (hostname)
end

View file

@ -0,0 +1,11 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_vfish
if set -q VIRTUAL_ENV
__fishline_segment $FLCLR_VFISH_BG $FLCLR_VFISH_FG
printf "$FLSYM_VFISH%s" (basename $VIRTUAL_ENV)
end
end

View file

@ -0,0 +1,27 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_vimode
if begin;
set -q __fish_vi_mode;
or [ "$__fish_active_key_bindings" = "fish_vi_key_bindings" ]
end
switch $fish_bind_mode
case default
__fishline_segment $FLCLR_VIMODE_DEFAULT_BG $FLCLR_VIMODE_DEFAULT_FG
printf $FLSYM_VIMODE_DEFAULT
case insert
__fishline_segment $FLCLR_VIMODE_INSERT_BG $FLCLR_VIMODE_INSERT_FG
printf $FLSYM_VIMODE_INSERT
case replace-one
__fishline_segment $FLCLR_VIMODE_REPLACE_BG $FLCLR_VIMODE_REPLACE_FG
printf $FLSYM_VIMODE_REPLACE
case visual
__fishline_segment $FLCLR_VIMODE_VISUAL_BG $FLCLR_VIMODE_VISUAL_FG
printf $FLSYM_VIMODE_VISUAL
end
end
end

View file

@ -0,0 +1,11 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function __flseg_write
if not test -w .
__fishline_segment $FLCLR_WRITE_BG $FLCLR_WRITE_FG
printf "$FLSYM_WRITE_LOCK"
end
end

View file

@ -0,0 +1,3 @@
function fish_mode_prompt
end

View file

@ -1,3 +1,5 @@
function fish_prompt
printf '%s%s%s♥%s %s%s%s%s%s%s☛ '(set_color $fish_color_user) $USER (set_color magenta) (set_color $fish_color_host) $hostname (set_color $fish_color_cwd) (prompt_pwd) (set_color green) (set_color normal)
source $HOME/.config/fish/conf.d/dracula-fishline.fish
fishline -s $status SIGSTATUS USERHOST FULLPWD GIT CLOCK N VIMODE
echo " "
end

View file

@ -1,7 +1,2 @@
function fish_right_prompt
set -g __fish_git_prompt_show_informative_status
set -g __fish_git_prompt_showupstream informative
set -g __fish_git_prompt_describe_style branch
set -g __fish_git_prompt_showcolorhints
fish_git_prompt
end

212
functions/fisher.fish Normal file
View file

@ -0,0 +1,212 @@
function fisher --argument-names cmd --description "A plugin manager for Fish"
set --query fisher_path || set --local fisher_path $__fish_config_dir
set --local fisher_version 4.3.1
set --local fish_plugins $__fish_config_dir/fish_plugins
switch "$cmd"
case -v --version
echo "fisher, version $fisher_version"
case "" -h --help
echo "Usage: fisher install <plugins...> Install plugins"
echo " fisher remove <plugins...> Remove installed plugins"
echo " fisher update <plugins...> Update installed plugins"
echo " fisher update Update all installed plugins"
echo " fisher list [<regex>] List installed plugins matching regex"
echo "Options:"
echo " -v or --version Print version"
echo " -h or --help Print this help message"
echo "Variables:"
echo " \$fisher_path Plugin installation path. Default: ~/.config/fish"
case ls list
string match --entire --regex -- "$argv[2]" $_fisher_plugins
case install update remove
isatty || read --local --null --array stdin && set --append argv $stdin
set --local install_plugins
set --local update_plugins
set --local remove_plugins
set --local arg_plugins $argv[2..-1]
set --local old_plugins $_fisher_plugins
set --local new_plugins
if ! set --query argv[2]
if test "$cmd" != update
echo "fisher: Not enough arguments for command: \"$cmd\"" >&2 && return 1
else if test ! -e $fish_plugins
echo "fisher: \"$fish_plugins\" file not found: \"$cmd\"" >&2 && return 1
end
set arg_plugins (string match --regex -- '^[^\s]+$' <$fish_plugins)
end
for plugin in $arg_plugins
test -e "$plugin" && set plugin (realpath $plugin)
contains -- "$plugin" $new_plugins || set --append new_plugins $plugin
end
if set --query argv[2]
for plugin in $new_plugins
if contains -- "$plugin" $old_plugins
test "$cmd" = remove &&
set --append remove_plugins $plugin ||
set --append update_plugins $plugin
else if test "$cmd" = install
set --append install_plugins $plugin
else
echo "fisher: Plugin not installed: \"$plugin\"" >&2 && return 1
end
end
else
for plugin in $new_plugins
contains -- "$plugin" $old_plugins &&
set --append update_plugins $plugin ||
set --append install_plugins $plugin
end
for plugin in $old_plugins
contains -- "$plugin" $new_plugins || set --append remove_plugins $plugin
end
end
set --local pid_list
set --local source_plugins
set --local fetch_plugins $update_plugins $install_plugins
echo (set_color --bold)fisher $cmd version $fisher_version(set_color normal)
for plugin in $fetch_plugins
set --local source (command mktemp -d)
set --append source_plugins $source
command mkdir -p $source/{completions,conf.d,functions}
fish --command "
if test -e $plugin
command cp -Rf $plugin/* $source
else
set temp (command mktemp -d)
set name (string split \@ $plugin) || set name[2] HEAD
set url https://api.github.com/repos/\$name[1]/tarball/\$name[2]
set header 'Accept: application/vnd.github.v3+json'
echo Fetching (set_color --underline)\$url(set_color normal)
if curl --silent -L -H \$header \$url | tar -xzC \$temp -f - 2>/dev/null
command cp -Rf \$temp/*/* $source
else
echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2
command rm -rf $source
end
command rm -rf \$temp
end
set files $source/* && string match --quiet --regex -- .+\.fish\\\$ \$files
" &
set --append pid_list (jobs --last --pid)
end
wait $pid_list 2>/dev/null
for plugin in $fetch_plugins
if set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] && test ! -e $source
if set --local index (contains --index -- "$plugin" $install_plugins)
set --erase install_plugins[$index]
else
set --erase update_plugins[(contains --index -- "$plugin" $update_plugins)]
end
end
end
for plugin in $update_plugins $remove_plugins
if set --local index (contains --index -- "$plugin" $_fisher_plugins)
set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files
if contains -- "$plugin" $remove_plugins
for name in (string replace --filter --regex -- '.+/conf\.d/([^/]+)\.fish$' '$1' $$plugin_files_var)
emit {$name}_uninstall
end
printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var
end
command rm -rf $$plugin_files_var
functions --erase (string replace --filter --regex -- '.+/functions/([^/]+)\.fish$' '$1' $$plugin_files_var)
for name in (string replace --filter --regex -- '.+/completions/([^/]+)\.fish$' '$1' $$plugin_files_var)
complete --erase --command $name
end
set --erase _fisher_plugins[$index]
set --erase $plugin_files_var
end
end
if set --query update_plugins[1] || set --query install_plugins[1]
command mkdir -p $fisher_path/{functions,conf.d,completions}
end
for plugin in $update_plugins $install_plugins
set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)]
set --local files $source/{functions,conf.d,completions}/*
if set --local index (contains --index -- $plugin $install_plugins)
set --local user_files $fisher_path/{functions,conf.d,completions}/*
set --local conflict_files
for file in (string replace -- $source/ $fisher_path/ $files)
contains -- $file $user_files && set --append conflict_files $file
end
if set --query conflict_files[1] && set --erase install_plugins[$index]
echo -s "fisher: Cannot install \"$plugin\": please remove or move conflicting files first:" \n" "$conflict_files >&2
continue
end
end
for file in (string replace -- $source/ "" $files)
command cp -Rf $source/$file $fisher_path/$file
end
set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files
set --query files[1] && set --universal $plugin_files_var (string replace -- $source $fisher_path $files)
contains -- $plugin $_fisher_plugins || set --universal --append _fisher_plugins $plugin
contains -- $plugin $install_plugins && set --local event install || set --local event update
printf "%s\n" Installing\ (set_color --bold)$plugin(set_color normal) " "$$plugin_files_var
for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var)
source $file
if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file)
emit {$name}_$event
end
end
end
command rm -rf $source_plugins
set --query _fisher_plugins[1] || set --erase _fisher_plugins
set --query _fisher_plugins &&
printf "%s\n" $_fisher_plugins >$fish_plugins ||
command rm -f $fish_plugins
set --local total (count $install_plugins) (count $update_plugins) (count $remove_plugins)
test "$total" != "0 0 0" && echo (string join ", " (
test $total[1] = 0 || echo "Installed $total[1]") (
test $total[2] = 0 || echo "Updated $total[2]") (
test $total[3] = 0 || echo "Removed $total[3]")
) plugin/s
case \*
echo "fisher: Unknown command: \"$cmd\"" >&2 && return 1
end
end
## Migrations ##
function _fisher_fish_postexec --on-event fish_postexec
if functions --query _fisher_list
fisher update >/dev/null 2>/dev/null
set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share
test -e $XDG_DATA_HOME/fisher && command rm -rf $XDG_DATA_HOME/fisher
functions --erase _fisher_list _fisher_plugin_parse
set --erase fisher_data
end
functions --erase _fisher_fish_postexec
end

81
functions/fishline.fish Normal file
View file

@ -0,0 +1,81 @@
#!/usr/bin/env fish
# -*- mode:fish; tab-width:4 -*-
function fishline -d "fishline prompt function"
set -g FLINT_POSITION left
set -g FLSYM_SEPARATOR $FLSYM_LEFT_SEPARATOR
set -g FLINT_FIRST true
set -g FLINT_LAST false
set -g FLINT_BCOLOR normal
set -g FLINT_PRINT_POST true
set -g FLINT_INVERT false
set -g FLINT_STATUS false
set -l prompt_segments $FLINE_DEFAULT_PROMPT
set -l args (getopt "lrxhvs:" $argv)
if [ $status -gt 0 ]
return 1
end
set args (echo $args | sed -E 's/^\s//;s/\ +/ /g' | tr ' ' '\n')
while [ (count $args) -ge 0 ]
switch $args[1]
case "-s"
set FLINT_STATUS $args[2]
set args $args[2..-1]
case "-r"
set FLINT_POSITION right
set FLSYM_SEPARATOR $FLSYM_RIGHT_SEPARATOR
case "-l"
set FLINT_POSITION left
set FLSYM_SEPARATOR $FLSYM_LEFT_SEPARATOR
case "-x"
functions -a | sed -nE 's/__flseg_([a-zA-Z_]+)/\1/p'
return 0
case "-h"
__fishline_usage
return 0
case "-v"
__fishline_version
return 0
case "--"
break
end
set args $args[2..-1]
end
if [ "$FLINT_STATUS" = "false" ]
if [ (count $args) -ge 2 ]; and [ "$args[2]" -eq "$args[2]" ]
set FLINT_STATUS $args[2]
if [ (count $args) -eq 2 ]
set args '--'
else
set args -- $args[3..-1]
end
else
echo "Warning: last status not passed as positional '-s' argument to fishline" >&2
set FLINT_STATUS 0
end
end
if [ (count $args) -gt 1 ]
set prompt_segments (echo $args[2..-1] | tr 'A-Z' 'a-z' | tr ' ' '\n')
else if set -q FLINE_PROMPT
set prompt_segments (echo $FLINE_PROMPT | tr 'A-Z' 'a-z' | tr ' ' '\n')
end
for seg in $prompt_segments
eval __flseg_$seg
end
__fishline_segment_close
set -e FLINT_FIRST
set -e FLINT_LAST
set -e FLINT_POSITION
set -e FLINT_STATUS
set -e FLINT_BCOLOR
set -e FLINT_INVERT
set -e FLINT_PRINT_POST
end