various improvements and changes

pull/179/head
Simon Let 3 years ago
parent 0c6ce3c8e9
commit 49ac6197d6
No known key found for this signature in database
GPG Key ID: D650C65DD46D431D
  1. 10
      cmd/collect/main.go
  2. 4
      cmd/config/main.go
  3. 2
      cmd/daemon/run-server.go
  4. 9
      cmd/install-utils/backup.go
  5. 25
      cmd/install-utils/main.go
  6. 10
      cmd/install-utils/migrate.go
  7. 2
      cmd/postcollect/main.go
  8. 62
      internal/cfg/cfg.go
  9. 7
      internal/cfg/migrate.go
  10. 49
      internal/device/device.go
  11. 18
      internal/deviceid/deviceid.go
  12. 4
      internal/output/output.go
  13. 18
      internal/recconv/recconv.go
  14. 1
      internal/recload/recload.go
  15. 22
      internal/record/v1.go
  16. 7
      internal/recordint/searchapp.go
  17. 8
      scripts/hooks.sh
  18. 30
      scripts/install.sh
  19. 38
      scripts/shellrc.sh
  20. 56
      scripts/util.sh

@ -54,8 +54,8 @@ func main() {
shell := flag.String("shell", "", "current shell")
logname := flag.String("logname", "", "$LOGNAME")
hostname := flag.String("hostname", "", "$HOSTNAME")
// logname := flag.String("logname", "", "$LOGNAME")
device := flag.String("device", "", "device name, usually $HOSTNAME")
// non-posix
shlvl := flag.Int("shlvl", -1, "$SHLVL")
@ -111,12 +111,12 @@ func main() {
Pwd: *pwd,
RealPwd: realPwd,
Logname: *logname,
Hostname: *hostname,
// Logname: *logname,
Device: *device,
GitOriginRemote: *gitRemote,
Time: time,
Time: fmt.Sprintf("%.4f", time),
PartOne: true,
PartsNotMerged: true,

@ -39,9 +39,9 @@ func main() {
case "port":
fmt.Println(config.Port)
case "sesswatchperiodseconds":
fmt.Println(config.SesswatchPeriodSeconds)
fmt.Println(config.SessionWatchPeriodSeconds)
case "sesshistinithistorysize":
fmt.Println(config.SesshistInitHistorySize)
fmt.Println(config.ReshHistoryMinSize)
default:
fmt.Println("Error: illegal --key!")
os.Exit(1)

@ -57,7 +57,7 @@ func (s *Server) Run() {
sesswatchSessionsToWatch,
sesswatchRecords,
sessionDropSubscribers,
s.config.SesswatchPeriodSeconds,
s.config.SessionWatchPeriodSeconds,
)
// handlers

@ -1,5 +1,14 @@
package main
func backup() {
panic("Backup not implemented yet!")
// Backup ~/.resh
// Backup xdg_data/resh/history.reshjson
// TODO: figure out history file localtions when using history sync
}
func rollback() {
panic("Rollback not implemented yet!")
// Rollback ~/.resh
// Rollback history
}

@ -1,7 +1,6 @@
package main
import (
"flag"
"fmt"
"os"
)
@ -12,17 +11,16 @@ var commit string
var developement bool
func main() {
var command string
flag.StringVar(&command, "command", "", "Utility to run")
flag.Parse()
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "ERROR: Not eonugh arguments\n")
printUsage(os.Stderr)
}
command := os.Args[1]
switch command {
case "backup":
backup()
case "rollback":
// FIXME
panic("Rollback not implemented yet!")
// rollback()
rollback()
case "migrate-config":
migrateConfig()
case "migrate-history":
@ -30,22 +28,23 @@ func main() {
case "help":
printUsage(os.Stdout)
default:
fmt.Fprintf(os.Stderr, "ERROR: Unknown command")
fmt.Fprintf(os.Stderr, "ERROR: Unknown command: %s\n", command)
printUsage(os.Stderr)
}
}
func printUsage(f *os.File) {
usage := `
Utils used during resh instalation
USAGE: ./install-utils COMMAND
Utils used during RESH instalation.
USAGE: ./install-utils COMMAND
COMMANDS:
COMMANDS:
backup backup resh installation and data
rollback restore resh installation and data from backup
migrate-config update config to reflect updates
migrate-history update history to reflect updates
help show this help
`
`
fmt.Fprintf(f, usage)
}

@ -19,7 +19,7 @@ func migrateConfig() {
os.Exit(1)
}
if changes {
fmt.Printf("Config file format has changed since last update - your config was updated to reflect the changes.\n")
fmt.Printf("RESH config file format has changed since last update - your config was updated to reflect the changes.\n")
}
}
@ -30,7 +30,11 @@ func migrateHistory() {
// }
// TODO: Find history in:
// - .resh/history.json (copy) - message user to delete the file once they confirm the new setup works
// - .resh_history.json (copy) - message user to delete the file once they confirm the new setup works
// - xdg_data/resh/history.reshjson
// - .resh_history.json
// - .resh/history.json
// Read xdg_data/resh/history.reshjson
// Write xdg_data/resh/history.reshjson
// the old format can be found in the backup dir
}

@ -84,7 +84,7 @@ func main() {
SessionID: *sessionID,
ExitCode: *exitCode,
Duration: duration,
Duration: fmt.Sprintf("%.4f", duration),
PartsNotMerged: true,
},

@ -44,12 +44,16 @@ type Config struct {
// Debug mode for search app
Debug bool
// SesswatchPeriodSeconds is how often should daemon check if terminal
// SessionWatchPeriodSeconds is how often should daemon check if terminal
// sessions are still alive
SesswatchPeriodSeconds uint
// SesshistInitHistorySize is how large resh history needs to be for
// There is not much need to adjust the value both memory overhead of watched sessions
// and the CPU overhead of chacking them are relatively low
SessionWatchPeriodSeconds uint
// ReshHistoryMinSize is how large resh history needs to be for
// daemon to ignore standard shell history files
SesshistInitHistorySize int
// Ignoring standard shell history gives us more consistent experience
// but you can increase this to something large to see standard shell history in RESH search
ReshHistoryMinSize int
}
// defaults for config
@ -59,10 +63,52 @@ var defaults = Config{
BindControlR: true,
Debug: false,
SesswatchPeriodSeconds: 600,
SesshistInitHistorySize: 1000,
SessionWatchPeriodSeconds: 600,
ReshHistoryMinSize: 1000,
}
const headerComment = `##
######################
## RESH config (v1) ##
######################
## Here you can find info about RESH configuration options.
## You can uncomment the options and custimize them.
## Required.
## The config format can change in future versions.
## ConfigVersion helps us seemlessly upgrade to the new formats.
# ConfigVersion = "v1"
## Port used by RESH daemon and rest of the components to communicate.
## Make sure to restart the daemon (pkill resh-daemon) when you change it.
# Port = 2627
## Controls how much and how detailed logs all RESH components produce.
## Use "debug" for full logs when you encounter an issue
## Options: "debug", "info", "warn", "error", "fatal"
# LogLevel = "info"
## When BindControlR is "true" RESH search app is bound to CTRL+R on terminal startuA
# BindControlR = true
## When Debug is "true" the RESH search app runs in debug mode.
## This is useful for development.
# Debug = false
## Daemon keeps track of running terminal sessions.
## SessionWatchPeriodSeconds controls how often daemon checks if the sessions are still alive.
## You shouldn't need to adjust this.
# SessionWatchPeriodSeconds = 600
## When RESH is first installed there is no RESH history so there is nothing to search.
## As a temporary woraround, RESH daemon parses bash/zsh shell history and searches it.
## Once RESH history is big enough RESH stops using bash/zsh history.
## ReshHistoryMinSize controls how big RESH history needs to be before this happens.
## You can increase this this to e.g. 10000 to get RESH to use bash/zsh history longer.
# ReshHistoryMinSize = 1000
`
func getConfigPath() (string, error) {
fname := "resh.toml"
xdgDir, found := os.LookupEnv("XDG_CONFIG_HOME")
@ -100,10 +146,10 @@ func processAndFillDefaults(configF *configFile) (Config, error) {
config.Port = *configF.Port
}
if configF.SesswatchPeriodSeconds != nil {
config.SesswatchPeriodSeconds = *configF.SesswatchPeriodSeconds
config.SessionWatchPeriodSeconds = *configF.SesswatchPeriodSeconds
}
if configF.SesshistInitHistorySize != nil {
config.SesshistInitHistorySize = *configF.SesshistInitHistorySize
config.ReshHistoryMinSize = *configF.SesshistInitHistorySize
}
var err error

@ -57,12 +57,19 @@ func Migrate() (bool, error) {
return true, nil
}
// writeConfig should only be used when migrating config to new version
// writing the config file discards all comments in the config file (limitation of TOML library)
// to make up for lost comments we add header comment to the start of the file
func writeConfig(config *configFile, path string) error {
file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0666)
if err != nil {
return fmt.Errorf("could not open config for writing: %w", err)
}
defer file.Close()
_, err = file.WriteString(headerComment)
if err != nil {
return fmt.Errorf("could not write config header: %w", err)
}
err = toml.NewEncoder(file).Encode(config)
if err != nil {
return fmt.Errorf("could not encode config: %w", err)

@ -0,0 +1,49 @@
package device
import (
"fmt"
"os"
"path"
"strings"
)
func GetID(dataDir string) (string, error) {
fname := "device-id"
dat, err := os.ReadFile(path.Join(dataDir, fname))
if err != nil {
return "", fmt.Errorf("could not read file with device-id: %w", err)
}
id := strings.TrimRight(string(dat), "\n")
return id, nil
}
func GetName(dataDir string) (string, error) {
fname := "device-name"
dat, err := os.ReadFile(path.Join(dataDir, fname))
if err != nil {
return "", fmt.Errorf("could not read file with device-name: %w", err)
}
name := strings.TrimRight(string(dat), "\n")
return name, nil
}
// TODO: implement, possibly with a better name
// func CheckID(dataDir string) (string, error) {
// fname := "device-id"
// dat, err := os.ReadFile(path.Join(dataDir, fname))
// if err != nil {
// return "", fmt.Errorf("could not read file with device-id: %w", err)
// }
// id := strings.TrimRight(string(dat), "\n")
// return id, nil
// }
//
// func CheckName(dataDir string) (string, error) {
// fname := "device-id"
// dat, err := os.ReadFile(path.Join(dataDir, fname))
// if err != nil {
// return "", fmt.Errorf("could not read file with device-id: %w", err)
// }
// id := strings.TrimRight(string(dat), "\n")
// return id, nil
// }

@ -1,18 +0,0 @@
package deviceid
import (
"fmt"
"os"
"path"
"strings"
)
func Get(dataDir string) (string, error) {
fname := "device-id"
dat, err := os.ReadFile(path.Join(dataDir, fname))
if err != nil {
return "", fmt.Errorf("could not read file with device-id: %w", err)
}
id := strings.TrimRight(string(dat), "\n")
return id, nil
}

@ -41,11 +41,13 @@ var msgDeamonNotRunning = `Resh-daemon didn't respond - it's probably not runnin
-> Try restarting this terminal window to bring resh-daemon back up
-> If the problem persists you can check resh-daemon logs: ~/.local/share/resh/log.json (or ~/$XDG_DATA_HOME/resh/log.json)
-> You can create an issue at: https://github.com/curusarn/resh/issues
`
var msgVersionMismatch = `This terminal session was started with different resh version than is installed now.
It looks like you updated resh and didn't restart this terminal.
-> Restart this terminal window to fix that
`
func (f *Output) ErrorDaemonNotRunning(err error) {
@ -67,7 +69,7 @@ func (f *Output) ErrorVersionMismatch(installedVer, terminalVer string) {
}
func (f *Output) FatalVersionMismatch(installedVer, terminalVer string) {
fmt.Fprintf(os.Stderr, "%s: %s\n\n(installed version: %s, this terminal version: %s)",
fmt.Fprintf(os.Stderr, "%s: %s\n(installed version: %s, this terminal version: %s)\n",
f.ErrPrefix, msgVersionMismatch, installedVer, terminalVer)
f.Logger.Fatal("Version mismatch",
zap.String("installed", installedVer),

@ -1,6 +1,8 @@
package recconv
import (
"fmt"
"github.com/curusarn/resh/internal/record"
)
@ -10,24 +12,24 @@ func LegacyToV1(r *record.Legacy) *record.V1 {
// Flags: 0,
DeviceID: r.MachineID,
SessionID: r.SessionID,
RecordID: r.RecordID,
CmdLine: r.CmdLine,
ExitCode: r.ExitCode,
DeviceID: r.ReshUUID,
SessionID: r.SessionID,
RecordID: r.RecordID,
Home: r.Home,
Pwd: r.Pwd,
RealPwd: r.RealPwd,
Logname: r.Login,
Hostname: r.Host,
// Logname: r.Login,
Device: r.Host,
GitOriginRemote: r.GitOriginRemote,
Time: r.RealtimeBefore,
Duration: r.RealtimeDuration,
Time: fmt.Sprintf("%.4f", r.RealtimeBefore),
Duration: fmt.Sprintf("%.4f", r.RealtimeDuration),
PartOne: r.PartOne,
PartsNotMerged: !r.PartsMerged,

@ -1 +0,0 @@
package recload

@ -6,24 +6,26 @@ type V1 struct {
// FIXME: is this the best way? .. what about string, separate fields, or something similar
Flags int `json:"flags"`
// cmdline, exitcode
CmdLine string `json:"cmdLine"`
ExitCode int `json:"exitCode"`
DeviceID string `json:"deviceID"`
SessionID string `json:"sessionID"`
// can we have a shorter uuid for record
RecordID string `json:"recordID"`
// cmdline, exitcode
CmdLine string `json:"cmdLine"`
ExitCode int `json:"exitCode"`
// paths
// TODO: Do we need both pwd and real pwd?
Home string `json:"home"`
Pwd string `json:"pwd"`
RealPwd string `json:"realPwd"`
// hostname + lognem (not sure if we actually need logname)
Logname string `json:"logname"`
Hostname string `json:"hostname"`
// hostname + logname (not sure if we actually need logname)
// Logname string `json:"logname"`
// Device is usually hostname but not stricly hostname
// It can be configured in RESH configuration
Device string `json:"device"`
// git info
// origin is the most important
@ -45,8 +47,10 @@ type V1 struct {
// Shlvl int `json:"shlvl"`
// time (before), duration of command
Time float64 `json:"time"`
Duration float64 `json:"duration"`
// time and duration are strings because we don't want unnecessary precision when they get serialized into json
// we could implement custom (un)marshalling but I don't see downsides of directly representing the values as strings
Time string `json:"time"`
Duration string `json:"duration"`
// these look like internal stuff

@ -2,6 +2,7 @@ package recordint
import (
"net/url"
"strconv"
"strings"
giturls "github.com/whilp/git-urls"
@ -37,17 +38,19 @@ func NewSearchAppFromCmdLine(cmdLine string) SearchApp {
// NewCliRecord from EnrichedRecord
func NewSearchApp(r *Indexed) SearchApp {
// TODO: we used to validate records with recutil.Validate()
// TODO: handle this error
time, _ := strconv.ParseFloat(r.Rec.Time, 64)
return SearchApp{
IsRaw: false,
SessionID: r.Rec.SessionID,
CmdLine: r.Rec.CmdLine,
Host: r.Rec.Hostname,
Host: r.Rec.Device,
Pwd: r.Rec.Pwd,
Home: r.Rec.Home,
// TODO: is this the right place to normalize the git remote
GitOriginRemote: normalizeGitRemote(r.Rec.GitOriginRemote),
ExitCode: r.Rec.ExitCode,
Time: r.Rec.Time,
Time: time,
Idx: r.Idx,
}

@ -19,10 +19,7 @@ __resh_collect() {
# non-posix
local __RESH_SHLVL="$SHLVL"
local __RESH_GIT_REMOTE; __RESH_GIT_REMOTE="$(git remote get-url origin 2>/dev/null)"
local __RESH_GIT_REMOTE_EXIT_CODE=$?
local __RESH_PID="$$" # current pid
# time
# __RESH_RT_BEFORE="$EPOCHREALTIME"
__RESH_RT_BEFORE=$(__resh_get_epochrealtime)
@ -41,17 +38,18 @@ __resh_collect() {
echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh revision: $(resh-collect -revision); resh revision of this terminal session: ${__RESH_REVISION})"
fi
fi
# TODO: change how resh-uuid is read
if [ "$__RESH_VERSION" = "$(resh-collect -version)" ] && [ "$__RESH_REVISION" = "$(resh-collect -revision)" ]; then
resh-collect -requireVersion "$__RESH_VERSION" \
-requireRevision "$__RESH_REVISION" \
-shell "$__RESH_SHELL" \
-device "$__RESH_HOST" \
-deviceID "$(cat ~/.resh/resh-uuid 2>/dev/null)" \
-sessionID "$__RESH_SESSION_ID" \
-recordID "$__RESH_RECORD_ID" \
-home "$__RESH_HOME" \
-logname "$__RESH_LOGIN" \
-pwd "$__RESH_PWD" \
-sessionPID "$__RESH_SESSION_PID" \
-hostname "$__RESH_HOST" \
-shlvl "$__RESH_SHLVL" \
-gitRemote "$__RESH_GIT_REMOTE" \
-time "$__RESH_RT_BEFORE" \

@ -31,7 +31,7 @@ if [ "$bash_too_old" = true ]; then
if [ "$login_shell" = bash ]; then
echo " > Your bash version is old."
echo " > Bash is also your login shell."
echo " > Updating to bash 4.3+ is strongly RECOMMENDED!"
echo " > Updating to bash 4.3+ is STRONGLY RECOMMENDED!"
else
echo " > Your bash version is old"
echo " > Bash is not your login shell so it should not be an issue."
@ -52,7 +52,7 @@ else
if [ "$login_shell" = zsh ]; then
echo " > Your zsh version is old."
echo " > Zsh is also your login shell."
echo " > Updating to Zsh 5.0+ is strongly RECOMMENDED!"
echo " > Updating to Zsh 5.0+ is STRONGLY RECOMMENDED!"
else
echo " > Your zsh version is old"
echo " > Zsh is not your login shell so it should not be an issue."
@ -93,12 +93,12 @@ fi
# # shellcheck disable=2034
# read -r x
echo
echo "Backing up previous installation"
# TODO: ~/.resh -> XDG_DATA/resh/rollback/
# TODO: ~/XDG_DATA/resh/history.reshjson -> XDG_DATA/resh/rollback/
#./bin/resh-install-utils backup
# TODO: ~/.resh -> XDG_DATA_HOME/resh/rollback/
# TODO: ~/XDG_DATA_HOME/resh/history.reshjson -> XDG_DATA/resh/rollback/
# TODO: what about legacy history locations
# TODO: ~/XDG_DATA/resh/log.json -> XDG_DATA/resh/rollback/
# TODO: ~/XDG_DATA_HOME/resh/log.json -> XDG_DATA/resh/rollback/
echo "Cleaning up installation directory ..."
rm ~/.resh/bin/* 2>/dev/null ||:
@ -107,6 +107,8 @@ rm ~/.resh/* 2>/dev/null 2>/dev/null ||:
# backward compatibility: We have a new location for resh history file
[ ! -f ~/.resh/history.json ] || mv ~/.resh/history.json ~/.resh_history.json
#[ ! -f ~/.resh_history.json ] || mv ~/.resh_history.json $XDG .resh_history.json
echo "Creating directories ..."
mkdir_if_not_exists() {
@ -117,8 +119,6 @@ mkdir_if_not_exists() {
mkdir_if_not_exists ~/.resh
mkdir_if_not_exists ~/.resh/bin
mkdir_if_not_exists ~/.resh/bash_completion.d
mkdir_if_not_exists ~/.resh/zsh_completion.d
mkdir_if_not_exists ~/.config
echo "Copying files ..."
@ -138,7 +138,7 @@ cp -f scripts/uuid.sh ~/.resh/bin/resh-uuid
cp -f bin/resh-{daemon,cli,control,collect,postcollect,session-init,config} ~/.resh/bin/
echo "Creating/updating config file ..."
./bin/resh-config-setup
./bin/resh-install-utils migrate-config
echo "Finishing up ..."
# Adding resh shellrc to .bashrc ...
@ -146,14 +146,14 @@ if [ ! -f ~/.bashrc ]; then
touch ~/.bashrc
fi
grep -q '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' ~/.bashrc ||\
echo -e '\n[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc # this line was added by RESH (Rich Enchanced Shell History)' >> ~/.bashrc
echo -e '\n[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc # this line was added by RESH (Rich Enhanced Shell History)' >> ~/.bashrc
# Adding bash-preexec to .bashrc ...
grep -q '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' ~/.bashrc ||\
echo -e '\n[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh # this line was added by RESH (Rich Enchanced Shell History)' >> ~/.bashrc
echo -e '\n[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh # this line was added by RESH (Rich Enhanced Shell History)' >> ~/.bashrc
# Adding resh shellrc to .zshrc ...
if [ -f ~/.zshrc ]; then
grep -q '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' ~/.zshrc ||\
echo -e '\n[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc # this line was added by RESH (Rich Enchanced Shell History)' >> ~/.zshrc
echo -e '\n[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc # this line was added by RESH (Rich Enhanced Shell History)' >> ~/.zshrc
fi
# Deleting zsh completion cache - for future use
@ -178,9 +178,6 @@ if [ -f ~/.resh/resh.pid ]; then
else
pkill -SIGTERM "resh-daemon" || true
fi
# daemon uses xdg path variables
# FIXME: this does not exist anymore
#__resh_set_xdg_home_paths
__resh_run_daemon
@ -195,6 +192,7 @@ info="---- Scroll down using arrow keys ----
#####################################
"
# FIMXE: update info - resh history path
info="$info
RESH SEARCH APPLICATION = Redesigned reverse search that actually works
@ -214,7 +212,7 @@ CHECK FOR UPDATES
HISTORY
Your resh history will be recorded to '~/.resh_history.json'
Look at it using e.g. following command (you might need to install jq)
$ tail -f ~/.resh_history.json | jq
$ cat ~/.resh_history.json | sed 's/^v[^{]*{/{/' | jq .
ISSUES & FEEDBACK
Please report issues to: https://github.com/curusarn/resh/issues

@ -12,67 +12,45 @@ PATH=$PATH:~/.resh/bin
# shellcheck source=reshctl.sh
. ~/.resh/reshctl.sh
__RESH_MACOS=0
__RESH_LINUX=0
__RESH_UNAME=$(uname)
if [ "$__RESH_UNAME" = "Darwin" ]; then
__RESH_MACOS=1
elif [ "$__RESH_UNAME" = "Linux" ]; then
__RESH_LINUX=1
else
echo "resh PANIC unrecognized OS"
fi
if [ -n "${ZSH_VERSION-}" ]; then
# shellcheck disable=SC1009
__RESH_SHELL="zsh"
__RESH_HOST="$HOST"
__RESH_HOSTTYPE="$CPUTYPE"
__resh_zsh_completion_init
elif [ -n "${BASH_VERSION-}" ]; then
__RESH_SHELL="bash"
__RESH_HOST="$HOSTNAME"
__RESH_HOSTTYPE="$HOSTTYPE"
__resh_bash_completion_init
else
echo "resh PANIC unrecognized shell"
echo "RESH PANIC: unrecognized shell - please report this to https://github.com/curusarn/resh/issues"
fi
# posix
# TODO: read this from resh-specific file
# create that file during install
__RESH_DEVICE="$__RESH_HOST"
__RESH_HOME="$HOME"
__RESH_LOGIN="$LOGNAME"
__RESH_SHELL_ENV="$SHELL"
__RESH_TERM="$TERM"
# non-posix
__RESH_RT_SESSION=$(__resh_get_epochrealtime)
__RESH_OSTYPE="$OSTYPE"
__RESH_MACHTYPE="$MACHTYPE"
# shellcheck disable=2155
export __RESH_VERSION=$(resh-collect -version)
# shellcheck disable=2155
export __RESH_REVISION=$(resh-collect -revision)
# FIXME: this does not exist anymore
# __resh_set_xdg_home_paths
__resh_run_daemon
[ "$(resh-config --key BindControlR)" = true ] && __resh_bind_control_R
# block for anything we only want to do once per session
# NOTE: nested shells are still the same session
# i.e. $__RESH_SESSION_ID will be set in nested shells
if [ -z "${__RESH_SESSION_ID+x}" ]; then
export __RESH_SESSION_ID; __RESH_SESSION_ID=$(__resh_get_uuid)
export __RESH_SESSION_PID="$$"
# TODO add sesson time
__resh_reset_variables
__resh_session_init
fi
# block for anything we only want to do once per shell
# NOTE: nested shells are new shells
# i.e. $__RESH_INIT_DONE will NOT be set in nested shells
if [ -z "${__RESH_INIT_DONE+x}" ]; then
preexec_functions+=(__resh_preexec)
precmd_functions+=(__resh_precmd)

@ -54,67 +54,16 @@ __resh_run_daemon() {
fi
if [ "$(uname)" = Darwin ]; then
# hotfix
# gnohup resh-daemon 2>&1 & disown
gnohup resh-daemon & disown
gnohup resh-daemon >/dev/null 2>/dev/null & disown
else
# TODO: switch to nohup for consistency once you confirm that daemon is
# not getting killed anymore on macOS
nohup resh-daemon & disown
#nohup resh-daemon 2>&1 & disown
nohup resh-daemon >/dev/null 2>/dev/null & disown
#setsid resh-daemon 2>&1 & disown
fi
}
__resh_bash_completion_init() {
# primitive check to find out if bash_completions are installed
# skip completion init if they are not
_get_comp_words_by_ref >/dev/null 2>/dev/null
[[ $? == 127 ]] && return
. ~/.resh/bash_completion.d/_reshctl
}
# TODO: redo this
__resh_zsh_completion_init() {
# NOTE: this is hacky - each completion needs to be added individually
# TODO: fix later
# fpath=(~/.resh/zsh_completion.d $fpath)
# we should be using fpath but that doesn't work well with oh-my-zsh
# so we are just adding it manually
# shellcheck disable=1090
if typeset -f compdef >/dev/null 2>&1; then
source ~/.resh/zsh_completion.d/_reshctl && compdef _reshctl reshctl
else
# fallback I guess
fpath=(~/.resh/zsh_completion.d $fpath)
__RESH_zsh_no_compdef=1
fi
# TODO: test and use this
# NOTE: this is not how globbing works
# for f in ~/.resh/zsh_completion.d/_*; do
# source ~/.resh/zsh_completion.d/_$f && compdef _$f $f
# done
}
__resh_session_init() {
# posix
local __RESH_COLS="$COLUMNS"
local __RESH_LANG="$LANG"
local __RESH_LC_ALL="$LC_ALL"
# other LC ?
local __RESH_LINES="$LINES"
local __RESH_PWD="$PWD"
# non-posix
local __RESH_SHLVL="$SHLVL"
# pid
local __RESH_PID; __RESH_PID=$(__resh_get_pid)
# time
local __RESH_TZ_BEFORE; __RESH_TZ_BEFORE=$(date +%z)
local __RESH_RT_BEFORE; __RESH_RT_BEFORE=$(__resh_get_epochrealtime)
if [ "$__RESH_VERSION" != "$(resh-session-init -version)" ]; then
# shellcheck source=shellrc.sh
source ~/.resh/shellrc
@ -136,5 +85,4 @@ __resh_session_init() {
-sessionId "$__RESH_SESSION_ID" \
-sessionPid "$__RESH_SESSION_PID"
fi
}

Loading…
Cancel
Save