diff --git a/.github/.DS_Store b/.github/.DS_Store new file mode 100644 index 0000000..dd0458e Binary files /dev/null and b/.github/.DS_Store differ diff --git a/.github/workflows/.DS_Store b/.github/workflows/.DS_Store new file mode 100644 index 0000000..1522fc5 Binary files /dev/null and b/.github/workflows/.DS_Store differ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..91dfde0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI + +on: push + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Install Fish + run: | + sudo apt-add-repository -yn ppa:fish-shell/release-3 + sudo apt-get update + sudo apt-get install -y fish + + - name: Install Tools + run: | + curl -sL https://git.io/fisher | source + fisher install jorgebucaran/fisher $GITHUB_WORKSPACE + test (humantime 11655400) = "3h 14m 15s" + shell: fish {0} \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index cf1ab25..a1c6ee7 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,24 +1,7 @@ -This is free and unencumbered software released into the public domain. +Copyright © Jorge Bucaran <> -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. +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: -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. +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 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. - -For more information, please refer to +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. \ No newline at end of file diff --git a/README.md b/README.md index 6a04ee8..7e672d0 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,25 @@ -# fish-humanize-duration +# humantime.fish -A [fish shell](https://fishshell.com) package to make a time interval human readable. +> Turn milliseconds into a human-readable string in [Fish](https://fishshell.com). -## Installation - -With [Fisher](https://github.com/jorgebucaran/fisher) - -``` -fisher add fishpkg/fish-humanize-duration -``` - -## Usage +You have the time in milliseconds and want to turn it into a human-readable string like "3h 14m 15s". ```fish sleep 1 -echo $CMD_DURATION | humanize_duration +humantime $CMD_DURATION 1s 5ms ``` -## License +> **Tip**: `$CMD_DURATION` is set by Fish to the running time of the last command in milliseconds. + +## Installation -Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. +Install with [Fisher](https://github.com/jorgebucaran/fisher): -In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. +```console +fisher install jorgebucaran/humantime.fish +``` + +## License -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 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. +[MIT](LICENSE.md) diff --git a/functions/humantime.fish b/functions/humantime.fish new file mode 100644 index 0000000..9dee609 --- /dev/null +++ b/functions/humantime.fish @@ -0,0 +1,13 @@ +function humantime -a ms -d "Turn milliseconds into a human-readable string" + set --query ms[1] || return + + set --local hours (math --scale=0 $ms / \(3600 x 1000\)) + set --local mins (math --scale=0 $ms / \(60 x 1000\) % 60) + set --local secs (math --scale=0 $ms / 1000 % 60) + + test $hours -gt 0 && set --local --append out $hours"h" + test $mins -gt 0 && set --local --append out $mins"m" + test $secs -gt 0 && set --local --append out $secs"s" + + set --query out && echo $out || echo $ms"ms" +end diff --git a/humanize_duration.fish b/humanize_duration.fish deleted file mode 100644 index 53b9d4b..0000000 --- a/humanize_duration.fish +++ /dev/null @@ -1,23 +0,0 @@ -function humanize_duration -d "Make a time interval human readable" - if not string length --quiet $argv - set --erase argv - read --line argv - end - set hours (math --scale=0 $argv/\(3600 \*1000\)) - set mins (math --scale=0 $argv/\(60 \*1000\) % 60) - set secs (math --scale=0 $argv/1000 % 60) - if test $hours -gt 0 - set --append output $hours"h" - end - if test $mins -gt 0 - set --append output $mins"m" - end - if test $secs -gt 0 - set --append output $secs"s" - end - if not set --query output - echo $argv"ms" - else - echo $output - end -end