Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposing a few improvements #1

Closed
afh opened this issue Oct 22, 2021 · 2 comments
Closed

Proposing a few improvements #1

afh opened this issue Oct 22, 2021 · 2 comments

Comments

@afh
Copy link

afh commented Oct 22, 2021

Just came across gh-install on HN. While reading through the script I saw a few opportunities to improve it. Hope this helps :)

  • Using a subshell to execute commands in a different directory avoids the need forpopd.
(
cd$tmp
extract $filename
PS3="Select binary: "
select bin in $(find * -type f -not -path "*$filename"); do break; done
)
  • Using alternatives in case-matches avoids duplicated commands
  • Instead of failing with "command not found" gh-install could check for non-standard dependencies using command
  • gh-install users probably care less about its internal in error messages than gh-install developers, hence a more generic error message could be more appropriate
            case $arg in
                *.tar.bz2|*.tbz2)  tar xjf $arg      ;;
                *.tar.gz|*tar.xz|*.tgz)   tar xzf $arg      ;;
                *.bz2)      bunzip2 $arg      ;;
                *.gz)       gunzip $arg       ;;
                *.tar)      tar xf $arg       ;;
                *.zip)      unzip $arg        ;;
                *.Z)        uncompress $arg   ;;
                *.rar)
                    rar=$(command -v rar)
                    if [ -z "$rar" ]; then echo "Please install the rar utility"; exit 1; fi
                    $rar x $arg
                    ;;
                *.jar)
                    jar=$(command -v jar)
                    if [ -z "$jar" ]; then echo "Please install the jar utility"; exit 1; fi
                    jar -xvf $arg
                    ;;
               *)          echo "Don't know how to unpack '$arg'" ;;
@redraw
Copy link
Owner

redraw commented Oct 22, 2021

Thanks for the tips!

I don't usually copy-paste scripts literally from the internet, but this extract() method was taken literally from https://unix.stackexchange.com/a/168/245465. I think I'll credit it, and apply your tips.

I used to do 7z x which handles many formats, but wasn't sure if it would be installed on most operating systems.

@afh
Copy link
Author

afh commented Oct 22, 2021

Glad you like the proposal for improvement.

While 7z might be a convenient utility it is an external dependency that usually isn't installed on most systems so use of tar(1), bunzip2(1), gunzip(1) is preferrable.

Giving credit where credit is due will be greatly appreciated :)

@redraw redraw closed this as completed Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants