hctx

package
v0.0.0-...-32cd23d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigCtxKey  hishtoryContextKey = "config"
	DbCtxKey      hishtoryContextKey = "db"
	HomedirCtxKey hishtoryContextKey = "homedir"
	BackendCtxKey hishtoryContextKey = "backend"
)

Variables

This section is empty.

Functions

func GetBackend

func GetBackend(ctx context.Context) shared.SyncBackend

GetBackend returns the sync backend from context. Returns nil if no backend has been set (caller should handle this case).

func GetConfigContents

func GetConfigContents() ([]byte, error)

func GetDb

func GetDb(ctx context.Context) *gorm.DB

func GetHome

func GetHome(ctx context.Context) string

func GetLogger

func GetLogger() *logrus.Logger

func InitConfig

func InitConfig() error

func MakeContext

func MakeContext() context.Context

func MakeHishtoryDir

func MakeHishtoryDir() error

func OpenLocalSqliteDb

func OpenLocalSqliteDb() (*gorm.DB, error)

func SetConfig

func SetConfig(config *ClientConfig) error

func WithBackend

func WithBackend(ctx context.Context, b shared.SyncBackend) context.Context

WithBackend returns a new context with the backend set.

Types

type ClientConfig

type ClientConfig struct {
	// The user secret that is used to derive encryption keys for syncing history entries
	UserSecret string `json:"user_secret" yaml:"-"`
	// Whether hishtory recording is enabled
	IsEnabled bool `json:"is_enabled" yaml:"-"`
	// A device ID used to track which history entry came from which device for remote syncing
	DeviceId string `json:"device_id" yaml:"-"`

	// Backend configuration for syncing
	// BackendType specifies the sync backend: "http" (default) or "s3"
	BackendType string `json:"backend_type,omitempty"`
	// S3Config holds configuration for the S3 backend (only used when BackendType is "s3")
	S3Config *S3BackendConfig `json:"s3_config,omitempty"`
	// Used for skipping history entries prefixed with a space in bash
	LastPreSavedHistoryLine string `json:"last_presaved_history_line" yaml:"-"`
	// Used for skipping history entries prefixed with a space in bash
	LastSavedHistoryLine string `json:"last_saved_history_line" yaml:"-"`
	// Used for uploading history entries that we failed to upload due to a missing network connection
	HaveMissedUploads     bool  `json:"have_missed_uploads" yaml:"-"`
	MissedUploadTimestamp int64 `json:"missed_upload_timestamp" yaml:"-"`
	// Used for uploading deletion requests that we failed to upload due to a missed network connection
	// Note that this is only applicable for deleting pre-saved entries. For interactive deletion, we just
	// show the user an error message if they're offline.
	PendingDeletionRequests []shared.DeletionRequest `json:"pending_deletion_requests" yaml:"-"`
	// Used for avoiding double imports of .bash_history
	HaveCompletedInitialImport bool `json:"have_completed_initial_import" yaml:"-"`
	// Whether control-r bindings are enabled
	ControlRSearchEnabled bool `json:"enable_control_r_search"`
	// The set of columns that the user wants to be displayed
	DisplayedColumns []string `json:"displayed_columns"`
	// Custom columns
	CustomColumns []CustomColumnDefinition `json:"custom_columns"`
	// Whether to force enable a compact mode for the TUI
	ForceCompactMode bool `json:"force_compact_mode"`
	// Whether this is an offline instance of hishtory with no syncing
	IsOffline bool `json:"is_offline"`
	// Whether duplicate commands should be displayed
	FilterDuplicateCommands bool `json:"filter_duplicate_commands"`
	// Whether to filter out commands that start with whitespace (space, tab, etc.)
	FilterWhitespacePrefix bool `json:"filter_whitespace_prefix,omitempty"`
	// A format string for the timestamp
	TimestampFormat string `json:"timestamp_format"`
	// Beta mode, enables unspecified additional beta features
	// Currently: This enables pre-saving of history entries to better handle long-running commands
	BetaMode bool `json:"beta_mode"`
	// Whether to highlight matches in search results
	HighlightMatches bool `json:"highlight_matches"`
	// Whether to enable AI completion
	AiCompletion bool `json:"ai_completion"`
	// Whether to enable presaving
	EnablePresaving bool `json:"enable_presaving"`
	// The current color scheme for the TUI
	ColorScheme ColorScheme `json:"color_scheme"`
	// A default filter that will be applied to all search queries
	DefaultFilter string `json:"default_filter"`
	// The endpoint to use for AI suggestions
	AiCompletionEndpoint string `json:"ai_completion_endpoint"`
	// Custom key bindings for the TUI
	KeyBindings keybindings.SerializableKeyMap `json:"key_bindings"`
	// The log level for hishtory (e.g., "debug", "info", "warn", "error")
	LogLevel logrus.Level `json:"log_level"`
	// Whether the TUI should render in full-screen mode
	FullScreenRendering bool `json:"full_screen_rendering"`
	// Columns that are used for default searches.
	// See https://github.com/ddworken/hishtory/issues/268 for context on this.
	DefaultSearchColumns []string `json:"default_search_columns"`
}

func GetConf

func GetConf(ctx context.Context) *ClientConfig

func GetConfig

func GetConfig() (ClientConfig, error)

type ColorScheme

type ColorScheme struct {
	SelectedText       string
	SelectedBackground string
	BorderColor        string
}

func GetDefaultColorScheme

func GetDefaultColorScheme() ColorScheme

type CustomColumnDefinition

type CustomColumnDefinition struct {
	ColumnName    string `json:"column_name"`
	ColumnCommand string `json:"column_command"`
}

type S3BackendConfig

type S3BackendConfig struct {
	// Bucket is the S3 bucket name (required)
	Bucket string `json:"bucket"`
	// Region is the AWS region (required)
	Region string `json:"region"`
	// Endpoint is a custom S3-compatible endpoint (optional, for MinIO, Backblaze, etc.)
	Endpoint string `json:"endpoint,omitempty"`
	// AccessKeyID is the AWS access key ID (optional if using IAM roles or env vars)
	AccessKeyID string `json:"access_key_id,omitempty"`
	// Prefix is an optional path prefix within the bucket (e.g., "hishtory/")
	Prefix string `json:"prefix,omitempty"`
}

S3BackendConfig holds configuration for the S3 sync backend. This is stored in the client config file (except for SecretAccessKey).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL