Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zsh): history loading with shared option #4071

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

LangLangBart
Copy link
Contributor

description

One of the zsh maintainers confirmed the use of fc -RI to resolve #4061.

Tested on 5.9 (latest release) and 5.0.1.

There is a bit of peculiarity, as the history array stands out as the only one among the history-related commands and widgets that needs a non-empty command to be entered in order to be updated.

https://zsh.org/mla/users/2024/msg00692.html


The changes should be sufficiently explained by the comments and the variable names themselves. Alternatively, the man pages for reading up on the syntax are listed below, and important aspects were extracted for ease of review.

# explains 'fc -RI'
man 1 zshbuiltins | less --pattern fc
# […] If the -I option is  added  to  -R,  onlythose  events that are
# not already contained within the internal history list are added.[…]

# explains 'zmodload -F … p:{…,…}
man 1 zshbuiltins | less --pattern zmodload
# Performs operations relating to zsh's loadable modules.  Loading
# of  modules  while the shell is running (`dynamical loading') is
# not available on all operating systems, or on all  installations
# on  a particular operating system […]

# zmodload  -F  allows more selective control over the fea-
# tures provided by modules.  With no  options  apart  from
# -F,  the  module  named  module  is loaded, if it was not
# already loaded, and the list of features is  set  to  the
# required state.  If no features are specified, the module
# is loaded, if it was not already loaded, but the state of
# features is unchanged.  Each feature may be preceded by a
# + to turn the feature on, or - to turn it off; the  +  is
# assumed if neither character is present.  Any feature not
# explicitly mentioned is left in its current state; if the
# module was not previously loaded this means any such fea-
# tures will remain disabled.  The return status is zero if
# all  features  were  set, 1 if the module failed to load,
# and 2 if some features could not be set […]

# The standard features are builtins,  conditions,  parame-
# ters  and math functions; these are indicated by the pre-
# fix `b:', `c:' (`C:' for an infix  condition),  `p:'  and
# `f:',  respectively, followed by the name that the corre-
# sponding feature would have in the shell.   For  example,
# `b:strftime'  indicates  a  builtin  named  strftime  and
# p:EPOCHSECONDS indicates a parameter named  EPOCHSECONDS.

# lists the cool things this module gives us
man 1 zshmodules | less --pattern "THE ZSH/PARAMETER MODULE"

# more context to the option
man 1 zshoptions | less --pattern SHARE_HISTORY

PS: It's possible for a user to explicitly disable a feature in their shell setup, which I can't imagine why anyone would ever do this.

# the module is loaded but the 'history' feature is disabled
zmodload -F zsh/parameter -p:history
zmodload -Fe zsh/parameter +p:history || echo "feature disabled"
# feature disabled

Currently, the code loads the module if not already, and the features are set. If this causes issues, which I currently don't foresee, we could modify the command to only check if the modules and features are enabled without enabling them:

if zmodload -Fe zsh/parameter +p:{commands,history,options} && …
  …

@junegunn junegunn merged commit d938fdc into junegunn:master Oct 31, 2024
5 checks passed
@junegunn
Copy link
Owner

Thank you!

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Nov 22, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [junegunn/fzf](https://github.com/junegunn/fzf) | minor | `v0.55.0` -> `v0.56.3` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>junegunn/fzf (junegunn/fzf)</summary>

### [`v0.56.3`](https://github.com/junegunn/fzf/releases/tag/v0.56.3): 0.56.3

[Compare Source](junegunn/fzf@v0.56.2...v0.56.3)

-   Bug fixes in zsh scripts
    -   fix(zsh): handle backtick trigger edge case ([#&#8203;4090](junegunn/fzf#4090))
    -   revert(zsh): remove 'fc -RI' call in the history widget ([#&#8203;4093](junegunn/fzf#4093))
    -   Thanks to [@&#8203;LangLangBart](https://github.com/LangLangBart) for the contributions

### [`v0.56.2`](https://github.com/junegunn/fzf/releases/tag/v0.56.2): 0.56.2

[Compare Source](junegunn/fzf@v0.56.1...v0.56.2)

-   Bug fixes
    -   Fixed abnormal scrolling behavior when `--wrap` is set ([#&#8203;4083](junegunn/fzf#4083))
    -   \[zsh] Fixed warning message when `ksh_arrays` is set ([#&#8203;4084](junegunn/fzf#4084))

### [`v0.56.1`](https://github.com/junegunn/fzf/releases/tag/v0.56.1): 0.56.1

[Compare Source](junegunn/fzf@v0.56.0...v0.56.1)

-   Bug fixes and improvements
    -   Fixed a race condition which would cause fzf to present stale results after `reload` ([#&#8203;4070](junegunn/fzf#4070))
    -   `page-up` and `page-down` actions now work correctly with multi-line items ([#&#8203;4069](junegunn/fzf#4069))
    -   `{n}` is allowed in `SCROLL` expression in `--preview-window` ([#&#8203;4079](junegunn/fzf#4079))
    -   \[zsh] Fixed regression in history loading with shared option ([#&#8203;4071](junegunn/fzf#4071))
    -   \[zsh] Better command extraction in zsh completion ([#&#8203;4082](junegunn/fzf#4082))
-   Thanks to [@&#8203;LangLangBart](https://github.com/LangLangBart), [@&#8203;jaydee-coder](https://github.com/jaydee-coder), [@&#8203;alex-huff](https://github.com/alex-huff), and [@&#8203;vejkse](https://github.com/vejkse) for the contributions

### [`v0.56.0`](https://github.com/junegunn/fzf/releases/tag/v0.56.0): 0.56.0

[Compare Source](junegunn/fzf@v0.55.0...v0.56.0)

-   Added `--gap[=N]` option to display empty lines between items.
    -   This can be useful to visually separate adjacent multi-line items.
        ```sh
        ```

### All bash functions, highlighted

      declare -f | perl -0777 -pe 's/^}\n/}\0/gm' |
        bat --plain --language bash --color always |
        fzf --read0 --ansi --reverse --multi --highlight-line --gap
      ```
      <img width="855" alt="image" src="https://github.com/user-attachments/assets/b3d2eaf2-bf44-4e3a-8d7b-9878629dd9be">
    - Or just to make the list easier to read. For single-line items, you probably want to set `--color gutter:-1` as well to hide the gutter.
      ```sh
      fzf --info inline-right --gap --color gutter:-1
      ```
      <img width="855" alt="image" src="https://github.com/user-attachments/assets/113757a1-ccfd-42a6-b946-83533f408e69">

-   Added `noinfo` option to `--preview-window` to hide the scroll indicator in the preview window
-   Bug fixes
    -   Thanks to [@&#8203;LangLangBart](https://github.com/LangLangBart), [@&#8203;akinomyoga](https://github.com/akinomyoga), and [@&#8203;charlievieth](https://github.com/charlievieth) for fixing the bugs

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ctrl+r no longer pulling from shared history until a command is run succesfully
2 participants