mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-11 05:39:45 +08:00
Compare commits
5 Commits
a6198e91f3
...
9ffe213255
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ffe213255 | ||
|
|
41c5b9677a | ||
|
|
116be8badd | ||
|
|
2bbd7156c3 | ||
|
|
6f7a50dca8 |
2
.github/workflows/dependencies.yml
vendored
2
.github/workflows/dependencies.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
contents: write # this is needed to push commits and branches
|
contents: write # this is needed to push commits and branches
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
|
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
4
.github/workflows/installer.yml
vendored
4
.github/workflows/installer.yml
vendored
@ -26,7 +26,7 @@ jobs:
|
|||||||
- macos-latest
|
- macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
|
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ jobs:
|
|||||||
- test
|
- test
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
|
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -24,7 +24,7 @@ jobs:
|
|||||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
|
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/project.yml
vendored
2
.github/workflows/project.yml
vendored
@ -17,7 +17,7 @@ jobs:
|
|||||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
|
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
- name: Authenticate as @ohmyzsh
|
- name: Authenticate as @ohmyzsh
|
||||||
|
|||||||
4
.github/workflows/scorecard.yml
vendored
4
.github/workflows/scorecard.yml
vendored
@ -36,7 +36,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
|
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@ -60,6 +60,6 @@ jobs:
|
|||||||
retention-days: 5
|
retention-days: 5
|
||||||
|
|
||||||
- name: "Upload to code-scanning"
|
- name: "Upload to code-scanning"
|
||||||
uses: github/codeql-action/upload-sarif@b20883b0cd1f46c72ae0ba6d1090936928f9fa30 # v4.32.0
|
uses: github/codeql-action/upload-sarif@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
# fancy-ctrl-z
|
# fancy-ctrl-z
|
||||||
|
|
||||||
Allows pressing Ctrl-Z again to switch back to a background job.
|
Allows pressing <kbd>Ctrl</kbd>-<kbd>Z</kbd> is an empty prompt to bring to the
|
||||||
|
foreground the only suspended job, or, if there are more than one such jobs, to
|
||||||
|
switch between the two most recently suspended ones.
|
||||||
|
|
||||||
To use it, add `fancy-ctrl-z` to the plugins array in your zshrc file:
|
To use it, add `fancy-ctrl-z` to the `plugins` array in your `.zshrc` file:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
plugins=(... fancy-ctrl-z)
|
plugins=(... fancy-ctrl-z)
|
||||||
@ -10,15 +12,29 @@ plugins=(... fancy-ctrl-z)
|
|||||||
|
|
||||||
## Motivation
|
## Motivation
|
||||||
|
|
||||||
I frequently need to execute random commands in my shell. To achieve it I pause
|
I frequently need to execute random commands in my shell.
|
||||||
Vim by pressing Ctrl-z, type command and press fg<Enter> to switch back to Vim.
|
To achieve it, I often pause Vim by pressing <kbd>Ctrl</kbd>-<kbd>Z</kbd>, type
|
||||||
The fg part really hurts me. I just wanted to hit Ctrl-z once again to get back
|
a command and then would use `fg`<kbd>↵ Enter</kbd> to switch back to Vim.
|
||||||
to Vim. I could not find a solution, so I developed one on my own that
|
Having to type in the `fg` part really hurt me.
|
||||||
works wonderfully with ZSH.
|
I just wanted to hit <kbd>Ctrl</kbd>-<kbd>Z</kbd> once again to get back to Vim.
|
||||||
|
I could not find a solution, so I developed one on my own that works wonderfully
|
||||||
|
with Zsh.
|
||||||
|
|
||||||
Source: http://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/
|
Switching between the last two suspended jobs is motivated by both TV remotes
|
||||||
|
that had such feature, and tools like `cd -` and `git checkout -` that switch
|
||||||
|
between the current and the second most recent state (directory, branch, etc.).
|
||||||
|
Sometimes, you have your Vim where code is changed, and another longer-running
|
||||||
|
process (e.g., a `tail` on some logs, or a Python interpreter) where you want
|
||||||
|
to test or observe your changes.
|
||||||
|
There is no point in time where you would "have the editor open" and "have the
|
||||||
|
program open" together, and the workflow clearly mandates always switching
|
||||||
|
back and forth between the two.
|
||||||
|
That's why the original version of _fancy-ctrl-z_ was extended with this "even
|
||||||
|
fancier" behaviour, because the original version would've opened Vim back again
|
||||||
|
and again.
|
||||||
|
|
||||||
Credits:
|
## Credits
|
||||||
- original idea by @sheerun
|
|
||||||
- added to OMZ by @mbologna
|
|
||||||
|
|
||||||
|
- Original idea by [@sheerun](https://github.com/sheerun), http://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity
|
||||||
|
- Added to OMZ by [@mbologna](https://github.com/mbologna)
|
||||||
|
- Two-job switching added by [@Whisperity](https://github.com/Whisperity)
|
||||||
|
|||||||
@ -1,12 +1,40 @@
|
|||||||
fancy-ctrl-z () {
|
fancy-ctrl-z () {
|
||||||
if [[ $#BUFFER -eq 0 ]]; then
|
local -i hascmd=$(( ${#BUFFER} > 0 ))
|
||||||
|
local -a sjobs=("${(@f)$(jobs -s)}")
|
||||||
|
local -a opts=("${(@f)$(setopt)}")
|
||||||
|
local -i isverbose=$opts[(Ie)verbose]
|
||||||
|
# In Zsh, arrays are 1-indexed, and an empty array has size 1, not 0.
|
||||||
|
# So we must check the first element's length to see whether it describes a
|
||||||
|
# suspended job.
|
||||||
|
local -i nsjobs="${#${(@)sjobs}}"
|
||||||
|
local -i hassjob=$(( ${#sjobs[1]} > 0 ))
|
||||||
|
local -i hassjobs=$(( nsjobs >= 2 ))
|
||||||
|
# Whether the ^Z action will result in a side effect to the terminal.
|
||||||
|
local -i sideeffect=$(( hassjob || hassjobs || isverbose ))
|
||||||
|
|
||||||
|
if (( hascmd && sideeffect )); then
|
||||||
|
# Save the current command.
|
||||||
|
# It will be restored after the side-effect is over, e.g., if the
|
||||||
|
# foregrounded job is put to the background again.
|
||||||
|
zle push-input -w
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( hassjobs )); then
|
||||||
|
# Multiple suspended jobs: foreground the second-to-last suspended job.
|
||||||
|
BUFFER="fg %-"
|
||||||
|
zle accept-line -w
|
||||||
|
elif (( hassjob )); then
|
||||||
|
# Single suspended job: foreground it.
|
||||||
|
# "fg %-" would result in an error as the only suspended job is the
|
||||||
|
# last one, which is referenced by "fg" or "fg %+".
|
||||||
|
BUFFER="fg %+"
|
||||||
|
zle accept-line -w
|
||||||
|
elif (( isverbose )); then
|
||||||
|
# No suspended jobs, but verbose mode, let show the "fg: no current job".
|
||||||
BUFFER="fg"
|
BUFFER="fg"
|
||||||
zle accept-line -w
|
zle accept-line -w
|
||||||
else
|
|
||||||
zle push-input -w
|
|
||||||
zle clear-screen -w
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
zle -N fancy-ctrl-z
|
zle -N fancy-ctrl-z
|
||||||
bindkey '^Z' fancy-ctrl-z
|
bindkey '^Z' fancy-ctrl-z
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user