diff options
author | Mateusz Czapliński <czapkofan@gmail.com> | 2018-10-31 18:28:12 +0100 |
---|---|---|
committer | Mateusz Czapliński <czapkofan@gmail.com> | 2018-10-31 18:37:16 +0100 |
commit | 970f01f183cd767389304b1b03a17ebf6d2f7c53 (patch) | |
tree | d2ea0a674ad9cf75711ceff919952f95dfbc3fdb | |
parent | a07cf8cbd1b4adf6fa7df6dbbb5ab68da202d3d0 (diff) |
refactor shell discovery
Closes #29 - thanks @rhnvrm for pointing out that readability of this
fragment of code could be improved!
-rw-r--r-- | up.go | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -92,19 +92,26 @@ func main() { // Find out what is the user's preferred login shell. This also allows user // to choose the "engine" used for command execution. + log.Println("checking $SHELL...") shell := os.Getenv("SHELL") - if shell == "" { - var err error - shell, err = exec.LookPath("bash") - if err == nil { + { + if shell != "" { goto shell_found } - shell, err = exec.LookPath("sh") - if err != nil { - die("cannot find shell: $SHELL is empty, neither bash nor sh are in $PATH") + log.Println("checking bash...") + shell, _ = exec.LookPath("bash") + if shell != "" { + goto shell_found + } + log.Println("checking sh...") + shell, _ = exec.LookPath("sh") + if shell != "" { + goto shell_found } + die("cannot find shell: $SHELL is empty, neither bash nor sh are in $PATH") + shell_found: + log.Println("found shell:", shell) } -shell_found: // Initialize TUI infrastructure tui := initTUI() |