-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shell,nix: set original PATH at start of init file (#57)
This fixes a bug that causes the devbox shell's init to fail when the user's rcfile tries to call a command outside of devbox. For example, the following line in a ~/.bashrc will trigger an error if the devbox doesn't have Go installed: export PATH="$(go env GOPATH):$PATH" This is because we're adding the ORIGINAL_PATH at the end of their shell init script, which means that anything before that only see Nix packages. Fix this by adding a pre-init hook that lets us restore the PATH before the user's rcfile, while still forcing Nix packages to come first in the post-init hook. --- In the process of testing and debugging this PR, I added a whole bunch of debug logging. It should probably be a separate commit, but I'm hesitant to touch anything now that things are working.
- Loading branch information
Showing
7 changed files
with
162 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package debug | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
var enabled bool | ||
|
||
func init() { | ||
enabled, _ = strconv.ParseBool(os.Getenv("DEBUG")) | ||
} | ||
|
||
func IsEnabled() bool { return enabled } | ||
|
||
func Enable() { | ||
enabled = true | ||
log.SetPrefix("[DEBUG] ") | ||
log.SetFlags(log.Llongfile | log.Ldate | log.Ltime) | ||
_ = log.Output(2, "Debug mode enabled.") | ||
} | ||
|
||
func Log(format string, v ...any) { | ||
if !enabled { | ||
return | ||
} | ||
_ = log.Output(2, fmt.Sprintf(format, v...)) | ||
} | ||
|
||
func Recover() { | ||
r := recover() | ||
if r == nil { | ||
return | ||
} | ||
|
||
if enabled { | ||
log.Println("Allowing panic because debug mode is enabled.") | ||
panic(r) | ||
} | ||
fmt.Println("Error:", r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters