fisher/functions/wait.fish
Jorge Bucaran 5dc1eea953
Ahoy! an early v0.7.0 is here!
+ Add  the ability  to install plugins  from Gists.  You can
distribute a very simple,  one-single function plugin in the
form  of a  Gist. Your  users  can install  it using  fisher
install  url and  Fisherman will  query the  Gist using  the
GitHub API to get a list of  the Gist files and use the name
of the  first identified *.fish  file to name the  plugin in
your system.  Since there is no  formal way to name  a Gist,
and you may  prefer to keep the "description"  field for the
actual description  and not a name,  Fisherman supports only
one fish file per Gist. Closes #75.

+ Use command(1) when calling non-builtins. Thanks @daenney.
Closes #79.

+  Add  __fisher_plugin_can_enable  to detect  installing  a
prompt that is not the current one. Closes #78.

+  Remove  the ability  to  install  a  plugin in  a  parent
directory using ..  or ../ or even worse, ../../  as well as
other combinations  that navigate  to a parent  directory. I
find  the use  case odd  at  best, and  more dangerous  that
useful.  If you  want  to  install a  local  plugin use  the
full  path  or a  relative  path,  always top  down.  fisher
install  . or  fisher  install my/plugin  or fisher  install
/Users/$USER/path/to/plugin. Closes #81.
2016-02-11 09:40:03 +09:00

140 lines
3.5 KiB
Fish
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function wait -d "Run commands and display a spinner"
set -l log
set -l time 0.02
set -l option
set -l commands
set -l spinners
set -l format " @\r"
getopts $argv | while read -l 1 2
switch "$1"
case _
set commands $commands ";$2"
case s spin
set spinners $spinners $2
case t time
set time $2
case l log
set log $2
case f format
set format $2
case help
set option help
case h
printf "usage: wait <commands> [--spin=<style>] [--time=<delay>] [--log=<file>] \n"
printf " [--format=<format>] [--help]\n\n"
printf " -s --spin=<style> Set spinner style\n"
printf " -t --time=<delay> Set spinner transition time delay\n"
printf " -l --log=<file> Output standard error to <file>\n"
printf " -f --format=<format> Use given <format> to display spinner\n"
printf " -h --help Show usage help\n"
return
case \*
printf "wait: '%s' is not a valid option\n" $1 > /dev/stderr
wait -h > /dev/stderr
return 1
end
end
switch "$option"
case help
man wait
return
end
if not set -q commands[1]
return 1
end
if not set -q spinners[1]
set spinners mixer
end
switch "$spinners"
case arc star pipe ball flip mixer caret
set -l arc "◜◠◝◞◡◟"
set -l star "+x*"
set -l pipe "|/--\\"
set -l ball "▖▘▝▗"
set -l flip "___-``'´-___"
set -l mixer "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
set -l caret "II||"
set spinners "$$spinners"
case bar{1,2,3}
set -l bar
set -l bar1 "[" "=" " " "]" "%"
set -l bar2 "[" "#" " " "]" "%"
set -l bar3 "." "." " " " " "%"
set -l open $$spinners[1][1]
set -l fill $$spinners[1][2]
set -l void $$spinners[1][3]
set -l close $$spinners[1][4]
set -l symbol $$spinners[1][5]
set spinners
for i in (seq 5 5 100)
if test -n "$symbol"
set symbol "$i%"
end
set -l gap (printf "$void%.0s" (seq (math 100 - $i)))
if test $i -ge 100
set gap ""
end
set spinners $spinners "$open"(printf "$fill%.0s" (seq $i))"$gap$close $symbol"
end
end
set -l tmp (mktemp -t wait.XXX)
fish -c "$commands" ^ $tmp &
if not set -q spinners[2]
set spinners (printf "%s\n" "$spinners" | grep -o .)
end
while true
if status --is-interactive
for i in $spinners
printf "$format" | awk -v i=(printf "%s\n" $i | sed 's/=/\\\=/') '
{
gsub("@", i)
printf("%s", $0)
}
' > /dev/stderr
sleep $time
end
end
if test -z (jobs)
break
end
end
if test -s $tmp
if test ! -z "$log"
nl -n command ln -- $tmp > $log
end
command rm -f $tmp
return 1
end
command rm -f $tmp
end