diff --git a/Makefile b/Makefile index 658df2b..f64196f 100644 --- a/Makefile +++ b/Makefile @@ -7,13 +7,15 @@ build: submodules resh-collect resh-daemon install: build | $(HOME)/.resh $(HOME)/.resh/bin $(HOME)/.config $(HOME)/.resh/resh-uuid cp submodules/bash-preexec/bash-preexec.sh ~/.bash-preexec.sh -f cp config.toml ~/.config/resh.toml -f - cp bashrc.sh ~/.resh/bashrc -f + cp shellrc.sh ~/.resh/shellrc -f cp resh-* ~/.resh/bin/ -f - grep '[[ -f ~/.resh/bashrc ]] && source ~/.resh/bashrc' ~/.bashrc ||\ - echo '[[ -f ~/.resh/bashrc ]] && source ~/.resh/bashrc' >> ~/.bashrc + grep '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' ~/.bashrc ||\ + echo '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' >> ~/.bashrc grep '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' ~/.bashrc ||\ echo '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> ~/.bashrc - -pkill resh-daemon + grep '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' ~/.zshrc ||\ + echo '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' >> ~/.zshrc + kill -SIGTERM $$(cat ~/.resh/resh.pid) nohup resh-daemon &>/dev/null & disown resh-daemon: daemon/resh-daemon.go common/resh-common.go diff --git a/bashrc.sh b/bashrc.sh deleted file mode 100644 index 1a6acdb..0000000 --- a/bashrc.sh +++ /dev/null @@ -1,91 +0,0 @@ - -PATH=$PATH:~/.resh/bin -export __RESH_RT_SESSION=$EPOCHREALTIME -export __RESH_RT_SESS_SINCE_BOOT=$(cat /proc/uptime | cut -d' ' -f1) -export __RESH_SESSION_ID=$(cat /proc/sys/kernel/random/uuid) -nohup resh-daemon &>/dev/null & disown - -preexec() { - # core - __RESH_COLLECT=1 - __RESH_CMDLINE="$1" - - # posix - __RESH_COLS="$COLUMNS" - __RESH_HOME="$HOME" - __RESH_LANG="$LANG" - __RESH_LC_ALL="$LC_ALL" - # other LC ? - __RESH_LINES="$LINES" - __RESH_LOGIN="$LOGNAME" - __RESH_PATH="$PATH" - __RESH_PWD="$PWD" - __RESH_SHELL="$SHELL" - __RESH_TERM="$TERM" - - # non-posix - __RESH_PID="$BASHPID" # current pid - __RESH_SHELL_PID="$$" # pid but subshells don't affect it - __RESH_WINDOWID="$WINDOWID" # session - __RESH_HOST="$HOSTNAME" - __RESH_HOSTTYPE="$HOSTTYPE" - __RESH_OSTYPE="$OSTYPE" - __RESH_MACHTYPE="$MACHTYPE" - __RESH_SHLVL="$SHLVL" - __RESH_GIT_CDUP="$(git rev-parse --show-cdup 2>/dev/null)" - __RESH_GIT_CDUP_EXIT_CODE=$? - __RESH_GIT_REMOTE="$(git remote get-url origin 2>/dev/null)" - __RESH_GIT_REMOTE_EXIT_CODE=$? - #__RESH_GIT_TOPLEVEL="$(git rev-parse --show-toplevel)" - #__RESH_GIT_TOPLEVEL_EXIT_CODE=$? - - # TODO: we should evaluate symlinks in preexec - # -> maybe create resh-precollect that could handle most of preexec - # maybe even move resh-collect here and send data to daemon and - # send rest of the data ($?, timeAfter) to daemon in precmd - # daemon will combine the data and save the record - # and save the unfinnished record even if it never finishes - # detect if the command died with the parent ps and save it then - - # time - __RESH_TZ_BEFORE=$(date +%:z) - __RESH_RT_BEFORE="$EPOCHREALTIME" -} - -precmd() { - __RESH_EXIT_CODE=$? - __RESH_RT_AFTER=$EPOCHREALTIME - __RESH_TZ_AFTER=$(date +%:z) - if [ ! -z ${__RESH_COLLECT+x} ]; then - resh-collect -cmdLine "$__RESH_CMDLINE" -exitCode "$__RESH_EXIT_CODE" \ - -cols "$__RESH_COLS" \ - -home "$__RESH_HOME" \ - -lang "$__RESH_LANG" \ - -lcAll "$__RESH_LC_ALL" \ - -lines "$__RESH_LINES" \ - -login "$__RESH_LOGIN" \ - -path "$__RESH_PATH" \ - -pwd "$__RESH_PWD" \ - -shell "$__RESH_SHELL" \ - -term "$__RESH_TERM" \ - -pid "$__RESH_PID" -shellPid "$__RESH_SHELL_PID" \ - -windowId "$__RESH_WINDOWID" \ - -host "$__RESH_HOST" \ - -hosttype "$__RESH_HOSTTYPE" \ - -ostype "$__RESH_OSTYPE" \ - -machtype "$__RESH_MACHTYPE" \ - -shlvl "$__RESH_SHLVL" \ - -gitCdup "$__RESH_GIT_CDUP" \ - -gitCdupExitCode "$__RESH_GIT_CDUP_EXIT_CODE" \ - -gitRemote "$__RESH_GIT_REMOTE" \ - -gitRemoteExitCode "$__RESH_GIT_REMOTE_EXIT_CODE" \ - -realtimeBefore "$__RESH_RT_BEFORE" \ - -realtimeAfter "$__RESH_RT_AFTER" \ - -realtimeSession "$__RESH_RT_SESSION" \ - -realtimeSessSinceBoot "$__RESH_RT_SESS_SINCE_BOOT" \ - -timezoneBefore "$__RESH_TZ_BEFORE" \ - -timezoneAfter "$__RESH_TZ_AFTER" - fi - unset __RESH_COLLECT -} - diff --git a/collect/resh-collect.go b/collect/resh-collect.go index 4c50b9f..a6cebbb 100644 --- a/collect/resh-collect.go +++ b/collect/resh-collect.go @@ -32,6 +32,7 @@ func main() { cmdLine := flag.String("cmdLine", "", "command line") exitCode := flag.Int("exitCode", -1, "exit code") + shell := flag.String("shell", "", "actual shell") // posix variables cols := flag.Int("cols", -1, "$COLUMNS") @@ -43,7 +44,7 @@ func main() { login := flag.String("login", "", "$LOGIN") path := flag.String("path", "", "$PATH") pwd := flag.String("pwd", "", "$PWD - present working directory") - shell := flag.String("shell", "", "$SHELL") + shellEnv := flag.String("shellEnv", "", "$SHELL") term := flag.String("term", "", "$TERM") // non-posix @@ -76,14 +77,20 @@ func main() { flag.Parse() realtimeAfter, err := strconv.ParseFloat(*rta, 64) + if err != nil { + log.Fatal("Flag Parsing error (rta):", err) + } realtimeBefore, err := strconv.ParseFloat(*rtb, 64) + if err != nil { + log.Fatal("Flag Parsing error (rtb):", err) + } realtimeSessionStart, err := strconv.ParseFloat(*rtsess, 64) if err != nil { - log.Fatal("Flag Parsing error (1):", err) + log.Fatal("Flag Parsing error (rt sess):", err) } realtimeSessSinceBoot, err := strconv.ParseFloat(*rtsessboot, 64) if err != nil { - log.Fatal("Flag Parsing error (2):", err) + log.Fatal("Flag Parsing error (rt sess boot):", err) } realtimeDuration := realtimeAfter - realtimeBefore realtimeSinceSessionStart := realtimeBefore - realtimeSessionStart @@ -109,19 +116,20 @@ func main() { // core CmdLine: *cmdLine, ExitCode: *exitCode, + Shell: *shell, // posix Cols: *cols, Lines: *lines, - Home: *home, - Lang: *lang, - LcAll: *lcAll, - Login: *login, - Path: *path, - Pwd: *pwd, - Shell: *shell, - Term: *term, + Home: *home, + Lang: *lang, + LcAll: *lcAll, + Login: *login, + Path: *path, + Pwd: *pwd, + ShellEnv: *shellEnv, + Term: *term, // non-posix RealPwd: realPwd, diff --git a/common/resh-common.go b/common/resh-common.go index 97a4bb1..4653e62 100644 --- a/common/resh-common.go +++ b/common/resh-common.go @@ -4,6 +4,7 @@ type Record struct { // core CmdLine string `json:"cmdLine"` ExitCode int `json:"exitCode"` + Shell string `json:"shell"` // posix Cols int `json:"cols"` @@ -14,7 +15,7 @@ type Record struct { Login string `json:"login"` Path string `json:"path"` Pwd string `json:"pwd"` - Shell string `json:"shell"` + ShellEnv string `json:"shellEnv"` Term string `json:"term"` // non-posix"`