This commit fixes a bug in the `getmark` function where it would not correctly handle non-existent marks. The previous implementation would swallow the error from `realpath`, causing the `||` condition to not be triggered.
This has been corrected by removing the command substitution and directly checking the exit code of `realpath`. The error message is now correctly printed to stderr, and the function returns a non-zero exit code on failure.
This commit refactors the `getmark` function in the `jump` plugin to improve its robustness and consistency with the rest of the file.
The `LANG=` prefix is added to ensure that the output of the `realpath` command is in a consistent, predictable format. The `command` prefix is used to bypass any potential aliases for `realpath` and `echo`, ensuring that the script executes the intended commands.
BREAKING CHANGE: Previously, `jump` would resolve the symlink to the mark directory and resolve again if the mark directory was also a symlink. It only resolves once after this commit.
- marks printed an error when $MARKPATH didn't exist or didn't have any marks
in it.
- The CTRL+G key binding overwrote an argument when it couldn't match it to
an existing mark.
- Fixes `readlink -e` dependency which isn't supported in macOS
(fixes#3235).
- Uses native zsh wildcard expansion instead of calls to `ls`.
- Prepends commands with `command` and `builtin` to bypass aliases
and functions.
- Documents CTRL+G key binding to substitute mark name in the command
line with the mark path (https://github.com/ohmyzsh/ohmyzsh/pull/2045#issuecomment-22826540).
Before, when typing the `marks` command, longer mark keys would cause
the tabs to spill over to the next tab stop, like so:
rc -> /home/ahlex/.rc
repos -> /home/ahlex/repos
a-longer-string -> /tmp
Implement better key display by running through all of the marks twice,
once to get the longest key length, and the second time to format
everything according to that length:
rc -> /home/ahlex/.rc
repos -> /home/ahlex/repos
a-longer-string -> /tmp
Using the `jump` plugin, using the `marks` command will yield this output:
```
$ marks
desktop marks:printf:5: bad option: ->
dotfiles marks:printf:5: bad option: ->
home marks:printf:5: bad option: ->
```
the `marks` function uses `printf` with `->` and I believe `-` is used by `printf` for left-justification. changing this to `-- "->"` seems to render the appropriate output.
```
desktop -> /Users/uname/Desktop
dotfiles -> /Users/uname/.dotfiles
home -> /Users/uname
```
This allows for the user to combine the jump command with something else. In my example cd and jump are now combined like this:
```bash
jumpcd() {
jump $1 > /dev/null || cd $1
}
alias cd="jumpcd"
```
Autocompletion fails if there's only one mark, since the ls command
will not display the parent directory with the trailing colon.
Handling the single mark case separately and validating the symlink
explicitly, resolves the issue.