Initial commit

This commit is contained in:
Abreu 2021-08-07 19:18:45 -03:00
commit 289ecdbd5e
8 changed files with 189 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
*
!README.md
!LICENSE
!*/
!**.fish
!.gitignore
dependency.fish

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 {{USER}}
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

46
README.md Normal file
View File

@ -0,0 +1,46 @@
# insist
> A plugin for [Oh My Fish][omf-link].
[![GPL License](https://img.shields.io/badge/license-GPL-blue.svg?longCache=true&style=flat-square)](/LICENSE)
[![Fish Shell Version](https://img.shields.io/badge/fish-v2.7.1-blue.svg?style=flat-square)](https://fishshell.com)
[![Oh My Fish Framework](https://img.shields.io/badge/Oh%20My%20Fish-Framework-blue.svg?style=flat-square)](https://www.github.com/oh-my-fish/oh-my-fish)
<br/>
## Description
Repeat a command until it succeeds. If no command is provided, perform the previous command.
## Options
`-q/--quiet`
Suppress attempt count.
`-c/--continue`
Continue to repeat the command line input after it's successful.
`-i/--interval [seconds]`
Interval between attempts. It can be followed by a suffix: 's' for seconds (the default), 'm' for minutes, 'h' for hours and 'd' for days.
`-n/--attempts [number]`
Set a maximum number of repetitions.
`-h/--help`
Display these instructions
## Install
```fish
omf repositories add https://gitlab.com/argonautica/argonautica
omf install insist
```
---
Ⓐ Made in Anarchy. No wage slaves were economically coerced into the making of this work.

12
completions/insist.fish Normal file
View File

@ -0,0 +1,12 @@
set -l cmd (status filename | command xargs basename | cut -f 1 -d '.')
source (status filename | command xargs dirname)/../dependency.fish
complete -c $cmd -n 'not contains_opts' -s h -l help \
-d 'Display instructions'
complete -c $cmd -n 'not contains_opts h help' -s q -l quiet \
-d 'Suppress attempt count.'
complete -c $cmd -n 'not contains_opts h help' -s c -l continue \
-d "Continue to repeat the command even after it's successful."
complete -xc $cmd -n 'not contains_opts h help' -s i -l interval \
-d 'Set interval between attempts.'
complete -xc $cmd -n 'not contains_opts h help' -s n -l attempts \
-d 'Set a maximum number of repetitions.'

64
functions/insist.fish Normal file
View File

@ -0,0 +1,64 @@
set -l cmd (command basename (status -f) | cut -f 1 -d '.')
function $cmd -V cmd -d "Perform a command repetitively until successful"
# Parse flags
set -l failed
if argparse -n $cmd 'h/help' 'q/quiet' 'c/continue' 'i/interval=' 'n/attempts=' -- $argv 2>&1 \
| read err
err $err
set failed true
end
if string match -qvr '^\d+[smhd]?$' $_flag_interval
err "$cmd: $_flag_interval: Invalid value"
set failed true
end
if string match -qvr '^0*[1-9]\d*$' $_flag_attempts
err "$cmd: $_flag_attempts: Invalid value"
set failed true
end
if test "$failed"
reg "Use |$cmd -h| to see examples of valid sintaxes"
return 1
end
# Display help
if set --query _flag_help
source (command dirname (status -f ))/../instructions.fish
not string length (set --names | string match -r '_flag_.+')$argv
return $status
end
# If no command is passed, perform the last used comamnd.
test "$argv"
or set argv (string replace -r '^insist' '' $history[1])
if test -z "$argv"
err "$cmd: No command was passed and there's no history of previous commands"
return 1
end
# Insist
set -l count 0
while true
set count (math $count + 1)
# Output, or not, the attempt count
if not set --query _flag_quiet
set --query _flag_attempts
and wrn -on "Insisting... Attempt $count of $_flag_attempts"
or wrn -on "Insisting... Attempt $count"
end
# Stop the function, or not, if the command was performed successfuly
if eval $argv
set --query _flag_continue
or break
end
# Stop the function if it met a given limit of attempts
test $count -eq "$_flag_attempts" 2>/dev/null
and break
set --query _flag_interval
and command sleep $_flag_interval
or command sleep 1
end
end

9
hooks/install.fish Normal file
View File

@ -0,0 +1,9 @@
if test (fish --version | string match -ar '\d' | string join '') -lt 300
set_color red
echo '$package: This plugin is compatible with fish version 3.0.0 or above, please update before retrying to install it' 1>&2
set_color normal
exit 1
end
command wget -qO $path/dependency.fish \
https://gitlab.com/argonautica/dependency/raw/master/dependency.fish
source $path/dependency.fish -n $package

1
hooks/uninstall.fish Normal file
View File

@ -0,0 +1 @@
source $path/subfunctions/dependency.fish -r

29
instructions.fish Normal file
View File

@ -0,0 +1,29 @@
set -l bld (set_color 00afff --bold);
set -l reg (set_color normal)
echo $bld"insist
""DESCRIPTION"$reg"
Repeat a command until it succeds. If no command is provided, perform the previous command.
"$bld"SYNTAX
"$bld"$cmd"$reg" [--quiet] [--continue] [--interval seconds] [--attempts number]
"$bld"OPTIONS
"$bld"-q/--quiet
Suppress attempt count.
"$bld"-c/--continue
Continue to repeat the command after it's successful.
"$bld"-i/--interval"$reg" [seconds]
Interval between attempts. It can be followed by a suffix: 's' for seconds (the default), 'm' for minutes, 'h' for hours and 'd' for days.
"$bld"-n/--attempts"$reg" [number]
Set a maximum number of repetitions.
"$bld"-h/--help"$reg"
Display these instructions.
" | less -R