Skip to main content
added 232 characters in body
Source Link

I faced a similar issue a number of times, and don't believe there is a clean solution available. You should be able to do some hackery to get this done. The most hackerish approach is probably to just dump the command to history without executing it by prefixing it with echo and then discarding !:0, after which your above solution would work.

The better approach would be hooking into ZSH's version of readline (zle if I remember correctly). It's a lot more powerful than regular readline and you can probably manipulate it in place without ever writing the bad command to history. I would suggest looking at existing plugins that expand the line automatically in-place as a starting point. A good example is this plugin: https://github.com/wazum/zsh-directory-dot-expansion (which expands ... to ../.. as you type). In fact, looking at that repo, you'd probably be able to get a plugin for this logic by changing 1-2 lines from the author's original script.

Note that you wouldn't be auto-expanding the zle as the user types, but react to some user key sequence (similar to alt+T combo you mention). So your plugin would be more similar to tab-completion than simple auto-expansion.

I faced a similar issue a number of times, and don't believe there is a clean solution available. You should be able to do some hackery to get this done. The most hackerish approach is probably to just dump the command to history without executing it by prefixing it with echo and then discarding !:0, after which your above solution would work.

The better approach would be hooking into ZSH's version of readline (zle if I remember correctly). It's a lot more powerful than regular readline and you can probably manipulate it in place without ever writing the bad command to history. I would suggest looking at existing plugins that expand the line automatically in-place as a starting point. A good example is this plugin: https://github.com/wazum/zsh-directory-dot-expansion (which expands ... to ../.. as you type). In fact, looking at that repo, you'd probably be able to get a plugin for this logic by changing 1-2 lines from the author's original script.

I faced a similar issue a number of times, and don't believe there is a clean solution available. You should be able to do some hackery to get this done. The most hackerish approach is probably to just dump the command to history without executing it by prefixing it with echo and then discarding !:0, after which your above solution would work.

The better approach would be hooking into ZSH's version of readline (zle if I remember correctly). It's a lot more powerful than regular readline and you can probably manipulate it in place without ever writing the bad command to history. I would suggest looking at existing plugins that expand the line automatically in-place as a starting point. A good example is this plugin: https://github.com/wazum/zsh-directory-dot-expansion (which expands ... to ../.. as you type). In fact, looking at that repo, you'd probably be able to get a plugin for this logic by changing 1-2 lines from the author's original script.

Note that you wouldn't be auto-expanding the zle as the user types, but react to some user key sequence (similar to alt+T combo you mention). So your plugin would be more similar to tab-completion than simple auto-expansion.

added 186 characters in body
Source Link

I faced a similar issue a number of times, and don't believe there is a clean solution available. You should be able to do some hackery to get this done. The most hackerish approach is probably to just dump the command to history without executing it by prefixing it with echo and then discarding !:0, after which your above solution would work.

The better approach would be hooking into ZSH's version of readline (zle if I remember correctly). It's a lot more powerful than regular readline and you can probably manipulate it in place without ever writing the bad command to history. I would suggest looking at existing plugins that expand the line automatically in-place as a starting point. A good example is this plugin: https://github.com/wazum/zsh-directory-dot-expansion (which expands ... to ../.. as you type). In fact, looking at that repo, you'd probably be able to get a plugin for this logic by changing 1-2 lines from the author's original script.

I faced a similar issue a number of times, and don't believe there is a clean solution available. You should be able to do some hackery to get this done. The most hackerish approach is probably to just dump the command to history without executing it by prefixing it with echo and then discarding !:0, after which your above solution would work.

The better approach would be hooking into ZSH's version of readline (zle if I remember correctly). It's a lot more powerful than regular readline and you can probably manipulate it in place without ever writing the bad command to history. I would suggest looking at existing plugins that expand the line automatically in-place as a starting point. A good example is this plugin: https://github.com/wazum/zsh-directory-dot-expansion.

I faced a similar issue a number of times, and don't believe there is a clean solution available. You should be able to do some hackery to get this done. The most hackerish approach is probably to just dump the command to history without executing it by prefixing it with echo and then discarding !:0, after which your above solution would work.

The better approach would be hooking into ZSH's version of readline (zle if I remember correctly). It's a lot more powerful than regular readline and you can probably manipulate it in place without ever writing the bad command to history. I would suggest looking at existing plugins that expand the line automatically in-place as a starting point. A good example is this plugin: https://github.com/wazum/zsh-directory-dot-expansion (which expands ... to ../.. as you type). In fact, looking at that repo, you'd probably be able to get a plugin for this logic by changing 1-2 lines from the author's original script.

Source Link

I faced a similar issue a number of times, and don't believe there is a clean solution available. You should be able to do some hackery to get this done. The most hackerish approach is probably to just dump the command to history without executing it by prefixing it with echo and then discarding !:0, after which your above solution would work.

The better approach would be hooking into ZSH's version of readline (zle if I remember correctly). It's a lot more powerful than regular readline and you can probably manipulate it in place without ever writing the bad command to history. I would suggest looking at existing plugins that expand the line automatically in-place as a starting point. A good example is this plugin: https://github.com/wazum/zsh-directory-dot-expansion.