mirror of
https://github.com/edu4rdshl/based.fish.git
synced 2026-07-18 07:34:45 +00:00
Compare commits
8 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa00038f28 | |||
| 62cd9b2f17 | |||
| 768bce39ec | |||
| 88cbb3cc9b | |||
| 2afe4b3aba | |||
| 0206728145 | |||
| b85004121f | |||
|
|
97525dd0e2 |
9 changed files with 75 additions and 10 deletions
14
README.md
14
README.md
|
|
@ -68,12 +68,20 @@ $ based stats
|
||||||
```
|
```
|
||||||
This will display statistics about your command usage, such as the most frequently used commands, options, and arguments.
|
This will display statistics about your command usage, such as the most frequently used commands, options, and arguments.
|
||||||
|
|
||||||
|
For database maintenance (recommended to run if you notice performance issues):
|
||||||
|
|
||||||
|
```fish
|
||||||
|
$ based maintenance
|
||||||
|
```
|
||||||
|
This will optimize the database by running VACUUM and ANALYZE operations to keep it performing well.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
You can customize the behavior of based.fish by setting environment variables in your Fish shell:
|
You can customize the behavior of based.fish by setting environment variables in your Fish shell:
|
||||||
|
|
||||||
- `BASED_NO_CONFIRMATION`: If set to `1`, automatically executes the selected suggestion without confirmation, otherwise, it requires another Enter key press to execute the suggestion.
|
- `BASED_NO_CONFIRMATION`: If set to `1`, automatically executes the selected suggestion without confirmation, otherwise, it requires another Enter key press to execute the suggestion.
|
||||||
- `BASED_NO_FUZZY`: If set to `1`, disables fuzzy matching for completions and only commands that start with the typed prefix will be suggested.
|
- `BASED_NO_FUZZY`: If set to `1`, disables fuzzy matching for completions and only commands that start with the typed prefix will be suggested.
|
||||||
|
- `BASED_EXCLUDED_PATHS`: A list of path patterns to exclude from history logging. Supports glob patterns like `*` and `?`. Useful for excluding temporary directories, sensitive locations, or paths where you don't want command history tracked.
|
||||||
|
|
||||||
E.g. to disable fuzzy behavior when searching for completions
|
E.g. to disable fuzzy behavior when searching for completions
|
||||||
|
|
||||||
|
|
@ -81,6 +89,12 @@ E.g. to disable fuzzy behavior when searching for completions
|
||||||
$ set -Ux BASED_NO_FUZZY 1
|
$ set -Ux BASED_NO_FUZZY 1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
E.g. to exclude specific paths from history tracking
|
||||||
|
|
||||||
|
```fish
|
||||||
|
$ set -Ux BASED_EXCLUDED_PATHS "/tmp/*" "/var/tmp/*" "$HOME/Downloads"
|
||||||
|
```
|
||||||
|
|
||||||
The keybindings for the completions are as follows:
|
The keybindings for the completions are as follows:
|
||||||
|
|
||||||
- `Arrow Up` and `Arrow Down`: Navigate through the suggestions of the smart history.
|
- `Arrow Up` and `Arrow Down`: Navigate through the suggestions of the smart history.
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@ complete -c based -n __fish_use_subcommand -f -a init -d "Initialize the Based d
|
||||||
complete -c based -n __fish_use_subcommand -f -a import -d "Import Fish history into Based"
|
complete -c based -n __fish_use_subcommand -f -a import -d "Import Fish history into Based"
|
||||||
complete -c based -n __fish_use_subcommand -f -a stats -d "Show Based statistics"
|
complete -c based -n __fish_use_subcommand -f -a stats -d "Show Based statistics"
|
||||||
complete -c based -n __fish_use_subcommand -f -a reset -d "Reset Based state"
|
complete -c based -n __fish_use_subcommand -f -a reset -d "Reset Based state"
|
||||||
|
complete -c based -n __fish_use_subcommand -f -a maintenance -d "Perform database maintenance"
|
||||||
complete -c based -n __fish_use_subcommand -f -a help -d "Show help message"
|
complete -c based -n __fish_use_subcommand -f -a help -d "Show help message"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Load the based logger (for fish_postexec event)
|
# Load the based logger (for fish_postexec event)
|
||||||
source ~/.config/fish/functions/__based_log.fish
|
source (status dirname)/../functions/__based_log.fish
|
||||||
# Load keybindings (↑ for smart history, Ctrl+g for fzf popup)
|
# Load keybindings (↑ for smart history, Ctrl+g for fzf popup)
|
||||||
source ~/.config/fish/functions/based_user_key_bindings.fish
|
source (status dirname)/../functions/based_user_key_bindings.fish
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,18 @@ function __based_fzf_popup
|
||||||
|
|
||||||
if test -n "$chosen"
|
if test -n "$chosen"
|
||||||
commandline -r -- "$chosen"
|
commandline -r -- "$chosen"
|
||||||
|
# Prevent autocomplete samples from remaining before the selected command.
|
||||||
|
# i.e: if you run `cd`, then arrow up, and select a command, the initial `cd` will be
|
||||||
|
# visible before the selected command, like: `cd cd <path>`. It doesn't affect functionality,
|
||||||
|
# but it can be visually confusing.
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
|
|
||||||
# Only execute if the user pressed ENTER and confirmation is set
|
# Only execute if the user pressed ENTER and confirmation is set
|
||||||
if test "$key" = enter; and set -q BASED_NO_CONFIRMATION; and test "$BASED_NO_CONFIRMATION" != 0
|
if test "$key" = enter; and set -q BASED_NO_CONFIRMATION; and test "$BASED_NO_CONFIRMATION" != 0
|
||||||
commandline -f execute
|
commandline -f execute
|
||||||
end
|
end
|
||||||
else
|
|
||||||
commandline -f repaint
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Update the display for commands like directory changes
|
||||||
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ function __based_init_db
|
||||||
CREATE INDEX IF NOT EXISTS idx_log_cmd ON log(cmd);
|
CREATE INDEX IF NOT EXISTS idx_log_cmd ON log(cmd);
|
||||||
CREATE INDEX IF NOT EXISTS idx_log_path_ts ON log(path, ts);
|
CREATE INDEX IF NOT EXISTS idx_log_path_ts ON log(path, ts);
|
||||||
CREATE INDEX IF NOT EXISTS idx_log_path_cmd ON log(path, cmd);
|
CREATE INDEX IF NOT EXISTS idx_log_path_cmd ON log(path, cmd);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_log_counter_ts ON log(counter DESC, ts DESC);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_log_cmd_like ON log(cmd COLLATE NOCASE);
|
||||||
"
|
"
|
||||||
|
|
||||||
echo "Based initialized. You can also import your fish history with 'based import'."
|
echo "Based initialized. You can also import your fish history with 'based import'."
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,15 @@ function __based_log --on-event fish_preexec
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Check if path should be excluded
|
||||||
|
if set -q BASED_EXCLUDED_PATHS
|
||||||
|
for excluded_pattern in $BASED_EXCLUDED_PATHS
|
||||||
|
if string match -q $excluded_pattern $path
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
set cmd (string replace -a "'" "''" -- $cmd)
|
set cmd (string replace -a "'" "''" -- $cmd)
|
||||||
set path (string replace -a "'" "''" -- $path)
|
set path (string replace -a "'" "''" -- $path)
|
||||||
|
|
||||||
|
|
|
||||||
25
functions/__based_maintenance.fish
Normal file
25
functions/__based_maintenance.fish
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
function __based_maintenance
|
||||||
|
set -l db ~/.local/share/fish/based/based.db
|
||||||
|
if not test -f $db
|
||||||
|
echo "Database not found. Run 'based init' first."
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Performing database maintenance..."
|
||||||
|
|
||||||
|
# Get database size before
|
||||||
|
set -l size_before (du -h $db | cut -f1)
|
||||||
|
|
||||||
|
# Vacuum the database
|
||||||
|
sqlite3 $db "VACUUM;"
|
||||||
|
|
||||||
|
# Update statistics
|
||||||
|
sqlite3 $db "ANALYZE;"
|
||||||
|
|
||||||
|
# Get database size after
|
||||||
|
set -l size_after (du -h $db | cut -f1)
|
||||||
|
|
||||||
|
echo "Database maintenance completed."
|
||||||
|
echo "Size before: $size_before"
|
||||||
|
echo "Size after: $size_after"
|
||||||
|
end
|
||||||
|
|
@ -3,5 +3,6 @@ function __based_reset_state
|
||||||
# Unset all variables related to Based state
|
# Unset all variables related to Based state
|
||||||
set -e BASED_NO_CONFIRMATION
|
set -e BASED_NO_CONFIRMATION
|
||||||
set -e BASED_NO_FUZZY
|
set -e BASED_NO_FUZZY
|
||||||
|
set -e BASED_EXCLUDED_PATHS
|
||||||
echo "Based state has been reset."
|
echo "Based state has been reset."
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,22 @@ function based
|
||||||
__based_stats
|
__based_stats
|
||||||
case reset
|
case reset
|
||||||
__based_reset_state
|
__based_reset_state
|
||||||
|
case maintenance vacuum
|
||||||
|
__based_maintenance
|
||||||
case help '*'
|
case help '*'
|
||||||
echo "Usage: based init|import|stats|reset|help"
|
echo "Usage: based init|import|stats|reset|maintenance|help"
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " init - Initialize the Based database"
|
echo " init - Initialize the Based database"
|
||||||
echo " import - Import fish history into Based"
|
echo " import - Import fish history into Based"
|
||||||
echo " stats - Show Based statistics"
|
echo " stats - Show Based statistics"
|
||||||
echo " reset - Reset Based state (clears variables)"
|
echo " reset - Reset Based state (clears variables)"
|
||||||
echo " help - Show this help message"
|
echo " maintenance - Perform database maintenance (vacuum & analyze)"
|
||||||
|
echo " help - Show this help message"
|
||||||
|
echo ""
|
||||||
|
echo "Configuration variables:"
|
||||||
|
echo " BASED_NO_CONFIRMATION - Skip confirmation prompts"
|
||||||
|
echo " BASED_NO_FUZZY - Disable fuzzy matching"
|
||||||
|
echo " BASED_EXCLUDED_PATHS - Paths to exclude from history (glob patterns)"
|
||||||
case '*'
|
case '*'
|
||||||
echo "Unknown command: $argv[1]"
|
echo "Unknown command: $argv[1]"
|
||||||
echo "Use 'based help' for usage information."
|
echo "Use 'based help' for usage information."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue