Introduce $fisher_cmd_name variable to customize fisher command name.

This commit is contained in:
Jorge Bucaran 2016-05-19 18:47:40 +09:00
parent 511f917ef8
commit 7259a3ee6a
No known key found for this signature in database
GPG key ID: E54BA3C0E646DB30
2 changed files with 311 additions and 314 deletions

View file

@ -34,7 +34,7 @@ curl -Lo ~/.config/fish/functions/fisher.fish --create-dirs git.io/fisherman
Install a plugin. Install a plugin.
``` ```
fisher sol fisher sol
``` ```
Install from multiple sources. Install from multiple sources.

View file

@ -1,4 +1,19 @@
function fisher if not set -q fisher_cmd_name
status --current-filename | command awk '
{
if (n = split($0, parts, "/")) {
gsub(/\.fish$/, "", parts[n])
print(parts[n])
} else {
print("fisher")
}
}
' | read -gx fisher_cmd_name
end
function $fisher_cmd_name
switch "$FISH_VERSION" switch "$FISH_VERSION"
case 2.1.2 2.1.1 2.1.0 2.0.0 case 2.1.2 2.1.1 2.1.0 2.0.0
__fisher_log error "You need fish @2.2.0@ or higher to use fisherman." __fisher_log error "You need fish @2.2.0@ or higher to use fisherman."
@ -82,10 +97,10 @@ function fisher
return 1 return 1
end end
set -l completions "$fish_config/completions/fisher.fish" set -l completions "$fish_config/completions/$fisher_cmd_name.fish"
if test ! -e "$completions" if test ! -e "$completions"
echo "fisher --complete" > "$completions" echo "$fisher_cmd_name --complete" > "$completions"
__fisher_complete __fisher_complete
end end
@ -154,7 +169,7 @@ function fisher
return return
case -\*\? case -\*\?
printf "fisher: '%s' is not a valid option\n" "$argv[1]" > /dev/stderr printf "$fisher_cmd_name: '%s' is not a valid option\n" "$argv[1]" > /dev/stderr
__fisher_usage > /dev/stderr __fisher_usage > /dev/stderr
return 1 return 1
@ -182,7 +197,7 @@ function fisher
" $__fisher_stderr " $__fisher_stderr
__fisher_log info " __fisher_log info "
See @fisher help@ for usage instructions. See @$fisher_cmd_name help@ for usage instructions.
" $__fisher_stderr " $__fisher_stderr
return return
end end
@ -336,7 +351,7 @@ function fisher
end end
end end
complete -c fisher --erase complete -c $fisher_cmd_name --erase
__fisher_complete __fisher_complete
end end
@ -622,11 +637,11 @@ end
function __fisher_self_update function __fisher_self_update
set -l file (status --current-filename) set -l file (status --current-filename)
if test "$file" != "$fish_config/functions/fisher.fish" if test "$file" != "$fish_config/functions/$fisher_cmd_name.fish"
return 1 return 1
end end
set -l completions "$fish_config/completions/fisher.fish" set -l completions "$fish_config/completions/$fisher_cmd_name.fish"
set -l raw_url "https://raw.githubusercontent.com/fisherman/fisherman/master/fisher.fish" set -l raw_url "https://raw.githubusercontent.com/fisherman/fisherman/master/fisher.fish"
set -l fake_qs (date "+%s") set -l fake_qs (date "+%s")
@ -642,11 +657,11 @@ function __fisher_self_update
builtin source "$file" ^ /dev/null builtin source "$file" ^ /dev/null
fisher -v > /dev/null echo "$fisher_cmd_name -v" | source > /dev/null
set -l new_version "$fisher_version" set -l new_version "$fisher_version"
echo "fisher --complete" > "$completions" echo "$fisher_cmd_name --complete" > "$completions"
builtin source "$completions" ^ /dev/null builtin source "$completions" ^ /dev/null
if test "$previous_version" = "$fisher_version" if test "$previous_version" = "$fisher_version"
@ -905,7 +920,7 @@ function __fisher_get_plugin_name_from_gist -a url
set -l gist_id (printf "%s\n" "$url" | command sed 's|.*/||') set -l gist_id (printf "%s\n" "$url" | command sed 's|.*/||')
set -l name (fish -c " set -l name (fish -c "
fisher -v > /dev/null $fisher_cmd_name -v > /dev/null
curl -Ss https://api.github.com/gists/$gist_id & curl -Ss https://api.github.com/gists/$gist_id &
__fisher_jobs_await (__fisher_jobs_get -l) __fisher_jobs_await (__fisher_jobs_get -l)
@ -1636,7 +1651,7 @@ function __fisher_plugin_get_missing
if test "$name" = fisherman if test "$name" = fisherman
__fisher_log info " __fisher_log info "
Run @fisher update@ to update fisherman. Run @$fisher_cmd_name update@ to update fisherman.
" > /dev/stderr " > /dev/stderr
continue continue
end end
@ -1846,24 +1861,26 @@ end
function __fisher_complete function __fisher_complete
complete -xc fisher -n "__fish_use_subcommand" -a install -d "Install plugins" complete -xc $fisher_cmd_name -n "__fish_use_subcommand" -a install -d "Install plugins"
complete -xc fisher -n "__fish_use_subcommand" -a update -d "Update plugins and self" complete -xc $fisher_cmd_name -n "__fish_use_subcommand" -a update -d "Update plugins and self"
complete -xc fisher -n "__fish_use_subcommand" -a rm -d "Remove plugins" complete -xc $fisher_cmd_name -n "__fish_use_subcommand" -a rm -d "Remove plugins"
complete -xc fisher -n "__fish_use_subcommand" -a ls -d "List what you've installed" complete -xc $fisher_cmd_name -n "__fish_use_subcommand" -a ls -d "List what you've installed"
complete -xc fisher -n "__fish_use_subcommand" -a ls-remote -d "List everything that's available" complete -xc $fisher_cmd_name -n "__fish_use_subcommand" -a ls-remote -d "List everything that's available"
complete -xc fisher -n "__fish_use_subcommand" -a help -d "Show help" complete -xc $fisher_cmd_name -n "__fish_use_subcommand" -a help -d "Show help"
complete -xc fisher -n "__fish_use_subcommand" -s h -l help -d "Show usage help" complete -xc $fisher_cmd_name -n "__fish_use_subcommand" -s h -l help -d "Show usage help"
complete -xc fisher -n "__fish_use_subcommand" -s v -l version -d "Show version information" complete -xc $fisher_cmd_name -n "__fish_use_subcommand" -s v -l version -d "Show version information"
complete -xc fisher -s q -l quiet -d "Enable quiet mode" complete -xc $fisher_cmd_name -s q -l quiet -d "Enable quiet mode"
complete -xc $fisher_cmd_name -n "__fish_seen_subcommand_from ls-remote" -l "format" -d "Customize format with verbs: %name, %url, %info and %stars"
set -l config_glob "$fisher_config"/* set -l config_glob "$fisher_config"/*
set -l config (printf "%s\n" $config_glob | command sed "s|.*/||") set -l config (printf "%s\n" $config_glob | command sed "s|.*/||")
if test ! -s "$fisher_cache/.index" if test ! -s "$fisher_cache/.index"
if test ! -z "$config" if test ! -z "$config"
complete -xc fisher -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$config" complete -xc $fisher_cmd_name -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$config"
complete -xc fisher -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$fisher_active_prompt" -d "Prompt" complete -xc $fisher_cmd_name -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$fisher_active_prompt" -d "Prompt"
end end
return return
end end
@ -1874,7 +1891,7 @@ function __fisher_complete
set -l path (command readlink "$name") set -l path (command readlink "$name")
set -l name (command basename "$name" | sed "s|$real_home|~|") set -l name (command basename "$name" | sed "s|$real_home|~|")
complete -xc fisher -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$name" -d "$path" complete -xc $fisher_cmd_name -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$name" -d "$path"
end end
set -l IFS \t set -l IFS \t
@ -1892,12 +1909,12 @@ function __fisher_complete
continue continue
end end
complete -xc fisher -n "__fish_seen_subcommand_from info ls-remote" -a "$name" -d "$info" complete -xc $fisher_cmd_name -n "__fish_seen_subcommand_from info ls-remote" -a "$name" -d "$info"
if contains -- "$name" $config if contains -- "$name" $config
complete -xc fisher -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$name" -d "$info" complete -xc $fisher_cmd_name -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$name" -d "$info"
else else
complete -xc fisher -n "__fish_seen_subcommand_from i in install" -a "$name" -d "$info" complete -xc $fisher_cmd_name -n "__fish_seen_subcommand_from i in install" -a "$name" -d "$info"
end end
end end
@ -1907,7 +1924,7 @@ function __fisher_complete
case fisherman\* case fisherman\*
case \* case \*
set -l name (__fisher_plugin_get_names "$i")[1] set -l name (__fisher_plugin_get_names "$i")[1]
complete -xc fisher -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$name" -d "$i" complete -xc $fisher_cmd_name -n "__fish_seen_subcommand_from l ls list u up update r rm remove" -a "$name" -d "$i"
end end
end end
end end
@ -1999,24 +2016,6 @@ function __fisher_parse_column_output
end end
function __fisher_parse_comments_from_function
command awk '
/^[\t ]*# ?/ {
sub(/^[\t ]*# ?/, "")
a[++n] = $0
}
END {
for (i = 1; i <= n; i++) {
printf("%s\n", a[i])
}
}
'
end
function __fisher_get_file_age -a file function __fisher_get_file_age -a file
if type -q perl if type -q perl
perl -e "printf(\"%s\n\", time - (stat ('$file'))[9])" ^ /dev/null perl -e "printf(\"%s\n\", time - (stat ('$file'))[9])" ^ /dev/null
@ -2031,7 +2030,7 @@ function __fisher_usage
set -l u (set_color -u) set -l u (set_color -u)
set -l nc (set_color normal) set -l nc (set_color normal)
echo "Usage: fisher [<command>] [<plugins>]" echo "Usage: $fisher_cmd_name [<command>] [<plugins>]"
echo echo
echo "where <command> is one of:" echo "where <command> is one of:"
echo " "$u"i"$nc"nstall (default)" echo " "$u"i"$nc"nstall (default)"
@ -2051,7 +2050,7 @@ end
function __fisher_help -a cmd number function __fisher_help -a cmd number
if test -z "$argv" if test -z "$argv"
set -l page "$fisher_cache/fisher.1" set -l page "$fisher_cache/$fisher_cmd_name.1"
if test ! -s "$page" if test ! -s "$page"
__fisher_man_page_write > "$page" __fisher_man_page_write > "$page"
@ -2094,7 +2093,7 @@ end
function __fisher_self_uninstall -a yn function __fisher_self_uninstall -a yn
set -l file (status --current-filename) set -l file (status --current-filename)
if test -z "$fish_config" -o -z "$fisher_cache" -o -z "$fisher_config" -o -L "$fisher_cache" -o -L "$fisher_config" -o "$file" != "$fish_config/functions/fisher.fish" if test -z "$fish_config" -o -z "$fisher_cache" -o -z "$fisher_config" -o -L "$fisher_cache" -o -L "$fisher_config" -o "$file" != "$fish_config/functions/$fisher_cmd_name.fish"
__fisher_log info "Abort: Non-standard setup detected." __fisher_log info "Abort: Non-standard setup detected."
return 1 return 1
@ -2112,8 +2111,8 @@ function __fisher_self_uninstall -a yn
$fisher_cache $fisher_cache
$fisher_config $fisher_config
$fish_config/functions/fisher.fish $fish_config/functions/$fisher_cmd_name.fish
$fish_config/completions/fisher.fish $fish_config/completions/$fisher_cmd_name.fish
" /dev/stderr " /dev/stderr
@ -2134,16 +2133,16 @@ function __fisher_self_uninstall -a yn
end end
end end
complete -c fisher --erase complete -c $fisher_cmd_name --erase
__fisher_show_spinner __fisher_show_spinner
fisher ls | fisher rm -q echo "__fisher_ls | fisher rm -q" | source ^ /dev/null
__fisher_show_spinner __fisher_show_spinner
command rm -rf "$fisher_cache" "$fisher_config" command rm -rf "$fisher_cache" "$fisher_config"
command rm -f "$fish_config"/{functions,completions}/fisher.fish "$fisher_file" command rm -f "$fish_config"/{functions,completions}/$fisher_cmd_name.fish "$fisher_file"
set -e fish_config set -e fish_config
set -e fisher_active_prompt set -e fisher_active_prompt
@ -2157,268 +2156,266 @@ function __fisher_self_uninstall -a yn
set -l funcs (functions -a | command grep __fisher) set -l funcs (functions -a | command grep __fisher)
functions -e $funcs fisher functions -e $funcs $fisher_cmd_name
end end
function __fisher_man_page_write function __fisher_man_page_write
functions __fisher_man_page_write | fish_indent | __fisher_parse_comments_from_function echo '.
.TH "FISHERMAN" "1" "May 2016" "" "fisherman"
.
.SH "NAME"
\fBfisherman\fR \- fish plugin manager
.
.SH "SYNOPSIS"
'"$fisher_cmd_name"' [(\-q | \-\-quiet)] [(\fBi\fRnstall | \fBu\fRpdate | \fBl\fRs[\-remote] | \fBr\fRm | \fBh\fRelp) PLUGINS]
.
.br
.
.SH "DESCRIPTION"
A plugin manager for fish\.
.
.SH "OPTIONS"
.
.IP "\(bu" 4
\-v, \-\-version: Show version information\.
.
.IP "\(bu" 4
\-h, \-\-help: Show usage help\. Use the long form to display this page\.
.
.IP "\(bu" 4
\-q, \-\-quiet: Enable quiet mode\. Use to suppress output\.
.
.IP "" 0
.
.SH "USAGE"
Install a plugin\.
.
.IP "" 4
.
.nf
# . '"$fisher_cmd_name"' sol
# .TH "FISHERMAN" "1" "May 2016" "" "fisherman" .
# . .fi
# .SH "NAME" .
# \fBfisherman\fR \- fish plugin manager .IP "" 0
# . .
# .SH "SYNOPSIS" .P
# fisher [(\-q | \-\-quiet)] [(\fBi\fRnstall | \fBu\fRpdate | \fBl\fRs[\-remote] | \fBr\fRm | \fBh\fRelp)] [PLUGIN\.\.\.] Install plugins from multiple sources\.
# . .
# .br .IP "" 4
# . .
# .SH "DESCRIPTION" .nf
# A plugin manager for fish\.
# . '"$fisher_cmd_name"' z fzf edc/bass omf/tab
# .SH "OPTIONS" .
# . .fi
# .IP "\(bu" 4 .
# \-v, \-\-version: Show version information\. .IP "" 0
# . .
# .IP "\(bu" 4 .P
# \-h, \-\-help: Show usage help\. Use the long form to display this page\. Install a gist\.
# . .
# .IP "\(bu" 4 .IP "" 4
# \-q, \-\-quiet: Enable quiet mode\. Use to suppress output\. .
# . .nf
# .IP "" 0
# . '"$fisher_cmd_name"' https://gist\.github\.com/username/1f40e1c6e0551b2666b2
# .SH "USAGE" .
# Install a plugin\. .fi
# . .
# .IP "" 4 .IP "" 0
# . .
# .nf .P
# Install a local directory as a plugin\.
# fisher sol .
# . .IP "" 4
# .fi .
# . .nf
# .IP "" 0
# . '"$fisher_cmd_name"' ~/plugin
# .P .
# Install plugins from multiple sources\. .fi
# . .
# .IP "" 4 .IP "" 0
# . .
# .nf .P
# Edit your \fIfishfile\fR and run \fB'"$fisher_cmd_name"'\fR to satisfy changes\.
# fisher z fzf edc/bass omf/tab .
# . .IP "" 4
# .fi .
# . .nf
# .IP "" 0
# . $EDITOR ~/\.config/fish/fishfile
# .P '"$fisher_cmd_name"'
# Install a gist\. .
# . .fi
# .IP "" 4 .
# . .IP "" 0
# .nf .
# .P
# fisher https://gist\.github\.com/username/1f40e1c6e0551b2666b2 List what you\'ve installed\.
# . .
# .fi .IP "" 4
# . .
# .IP "" 0 .nf
# .
# .P '"$fisher_cmd_name"' ls
# Install a local directory as a plugin\. @ plugin # a local directory
# . * sol # the current prompt
# .IP "" 4 bass
# . fzf
# .nf tab
# z
# fisher ~/plugin .
# . .fi
# .fi .
# . .IP "" 0
# .IP "" 0 .
# . .P
# .P List everything that\'s available\.
# Edit your \fIfishfile\fR and run \fBfisher\fR to satisfy changes\. .
# . .IP "" 4
# .IP "" 4 .
# . .nf
# .nf
# '"$fisher_cmd_name"' ls\-remote
# $EDITOR ~/\.config/fish/fishfile .
# fisher .fi
# . .
# .fi .IP "" 0
# . .
# .IP "" 0 .P
# . Update everything\.
# .P .
# List what you\'ve installed\. .IP "" 4
# . .
# .IP "" 4 .nf
# .
# .nf '"$fisher_cmd_name"' up
# .
# fisher ls .fi
# @ plugin # a local directory .
# * sol # the current prompt .IP "" 0
# bass .
# fzf .P
# tab Update some plugins\.
# z .
# . .IP "" 4
# .fi .
# . .nf
# .IP "" 0
# . '"$fisher_cmd_name"' up bass z fzf
# .P .
# List everything that\'s available\. .fi
# . .
# .IP "" 4 .IP "" 0
# . .
# .nf .P
# Remove plugins\.
# fisher ls\-remote .
# . .IP "" 4
# .fi .
# . .nf
# .IP "" 0
# . '"$fisher_cmd_name"' rm thefuck
# .P .
# Update everything\. .fi
# . .
# .IP "" 4 .IP "" 0
# . .
# .nf .P
# Remove all the plugins\.
# fisher up .
# . .IP "" 4
# .fi .
# . .nf
# .IP "" 0
# . '"$fisher_cmd_name"' ls | '"$fisher_cmd_name"' rm
# .P .
# Update some plugins\. .fi
# . .
# .IP "" 4 .IP "" 0
# . .
# .nf .P
# Get help\.
# fisher up bass z fzf .
# . .IP "" 4
# .fi .
# . .nf
# .IP "" 0
# . '"$fisher_cmd_name"' help z
# .P .
# Remove plugins\. .fi
# . .
# .IP "" 4 .IP "" 0
# . .
# .nf .P
# Uninstall fisherman\.
# fisher rm thefuck .
# . .IP "" 4
# .fi .
# . .nf
# .IP "" 0
# . '"$fisher_cmd_name"' self\-uninstall
# .P .
# Remove all the plugins\. .fi
# . .
# .IP "" 4 .IP "" 0
# . .
# .nf .SH "FAQ"
# .
# fisher ls | fisher rm .SS "What is the required fish version?"
# . >=2\.2\.0\.
# .fi .
# . .P
# .IP "" 0 For \fIsnippet\fR support, upgrade to >=2\.3\.0 or append the following code to your \fI~/\.config/fish/config\.fish\fR\.
# . .
# .P .IP "" 4
# Get help\. .
# . .nf
# .IP "" 4
# . for file in ~/\.config/fish/conf\.d/*\.fish
# .nf source $file
# end
# fisher help z .
# . .fi
# .fi .
# . .IP "" 0
# .IP "" 0 .
# . .SS "Is fisherman compatible with oh\-my\-fish themes and plugins?"
# .P Yes\.
# Uninstall fisherman\. .
# . .SS "Where does fisherman put stuff?"
# .IP "" 4 The cache and configuration go in \fI~/\.cache/fisherman\fR and \fI~/\.config/fisherman\fR respectively\.
# . .
# .nf .P
# The fishfile is saved to \fI~/\.config/fish/fishfile\fR\.
# fisher self\-uninstall .
# . .SS "What is a fishfile and how do I use it?"
# .fi The fishfile lists all the installed plugins\.
# . .
# .IP "" 0 .P
# . You can let fisherman take care of this file for you automatically, or write in the plugins you want and run \fBfisher\fR to satisfy the changes\.
# .SH "FAQ" .
# . .P
# .SS "What is the required fish version?" This mechanism only installs plugins and missing dependencies\. To remove plugins, use \fBfisher rm\fR\.
# >=2\.2\.0\. .
# . .SS "What is a plugin?"
# .P A plugin is:
# For \fIsnippet\fR support, upgrade to >=2\.3\.0 or append the following code to your \fI~/\.config/fish/config\.fish\fR\. .
# . .IP "1." 4
# .IP "" 4 a directory or git repo with one or more \fI\.fish\fR functions either at the root level of the project or inside a \fIfunctions\fR directory
# . .
# .nf .IP "2." 4
# a theme or prompt, i\.e, a \fIfish_prompt\.fish\fR, \fIfish_right_prompt\.fish\fR or both files
# for file in ~/\.config/fish/conf\.d/*\.fish .
# source $file .IP "3." 4
# end a snippet, i\.e, one or more \fI\.fish\fR files inside a directory named \fIconf\.d\fR, evaluated by fish at the start of the session
# . .
# .fi .IP "" 0
# . .
# .IP "" 0 .SS "How can I list plugins as dependencies to my plugin?"
# . Create a new \fIfishfile\fR file at the root level of your project and write in your plugin dependencies\.'
# .SS "Is fisherman compatible with oh\-my\-fish themes and plugins?"
# Yes\.
# .
# .SS "Where does fisherman put stuff?"
# The cache and configuration go in \fI~/\.cache/fisherman\fR and \fI~/\.config/fisherman\fR respectively\.
# .
# .P
# The fishfile is saved to \fI~/\.config/fish/fishfile\fR\.
# .
# .SS "What is a fishfile and how do I use it?"
# The fishfile lists all the installed plugins\.
# .
# .P
# You can let fisherman take care of this file for you automatically, or write in the plugins you want and run \fBfisher\fR to satisfy the changes\.
# .
# .P
# This mechanism only installs plugins and missing dependencies\. To remove plugins, use \fBfisher rm\fR\.
# .
# .SS "What is a plugin?"
# A plugin is:
# .
# .IP "1." 4
# a directory or git repo with one or more \fI\.fish\fR functions either at the root level of the project or inside a \fIfunctions\fR directory
# .
# .IP "2." 4
# a theme or prompt, i\.e, a \fIfish_prompt\.fish\fR, \fIfish_right_prompt\.fish\fR or both files
# .
# .IP "3." 4
# a snippet, i\.e, one or more \fI\.fish\fR files inside a directory named \fIconf\.d\fR, evaluated by fish at the start of the session
# .
# .IP "" 0
# .
# .SS "How can I list plugins as dependencies to my plugin?"
# Create a new \fIfishfile\fR file at the root level of your project and write in your plugin dependencies\.
end end