Skip to content

Feat: Implement Persistent Command History #84

@Shoury-Rana

Description

@Shoury-Rana

Description

Currently, PromptShell's command history is stored in-memory and is lost when the user exits the session. This is unlike standard shells like bash or zsh, where users can press the up arrow to access commands from previous sessions.

This feature request proposes implementing persistent command history, so that commands are saved to a file on exit and reloaded on startup.

Proposed Solution

The readline library, which is already in use, has built-in support for this functionality. The implementation should:

  1. Define a history file path: The history file should be stored in the application's config directory (e.g., ~/.config/PromptShell/history.log on Linux/macOS).
  2. Load history on startup: When setup_readline() is called, it should check for the existence of the history file and load it using readline.read_history_file().
  3. Save history on exit: Use the atexit module to register readline.write_history_file() to be called automatically when the application terminates. This ensures history is saved even on unexpected exits.
  4. Limit history size: It's good practice to set a reasonable limit on the number of commands stored using readline.set_history_length().

Benefits

  • Major Usability Improvement: Aligns PromptShell with user expectations for modern shell environments.
  • Improved Workflow: Saves users from re-typing complex commands from previous sessions.
  • Enhanced Productivity: Allows users to easily recall and reuse their work.

Will you make a PR?

  • Yes ✅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions