2025-06-24 12:46:21 +05:30
|
|
|
package alias
|
|
|
|
|
|
2026-01-11 19:25:13 +05:30
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
2025-06-24 12:46:21 +05:30
|
|
|
|
|
|
|
|
type Shell interface {
|
|
|
|
|
Source(rcPath string) string
|
|
|
|
|
Name() string
|
|
|
|
|
Path() string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var commentForRemovingShellSource = "# remove aliases by running `pmg setup remove` or deleting the line"
|
|
|
|
|
|
|
|
|
|
func defaultShellSource(rcPath string) string {
|
2026-01-01 12:33:52 +05:30
|
|
|
return fmt.Sprintf("%s \n[ -f '%s' ] && source '%s' # PMG source aliases\n", commentForRemovingShellSource, rcPath, rcPath)
|
2025-06-24 12:46:21 +05:30
|
|
|
}
|
2026-01-11 19:25:13 +05:30
|
|
|
|
|
|
|
|
// DetectShell attempts to detect the current shell from the SHELL environment variable.
|
|
|
|
|
func DetectShell() (string, error) {
|
|
|
|
|
shellEnv := os.Getenv("SHELL")
|
|
|
|
|
if shellEnv == "" {
|
|
|
|
|
return "", fmt.Errorf("SHELL environment variable not set")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parts := strings.Split(shellEnv, "/")
|
|
|
|
|
shellName := parts[len(parts)-1]
|
|
|
|
|
|
|
|
|
|
return shellName, nil
|
|
|
|
|
}
|