Is it possible to replace or remove `/home/username/` in the output when using `zoxide query -i`?
Hello there. Hope you're doing well. Thank you for creating zoxide. It has been an indispensable tool in my day-to-day workflow.
However, I'm wondering if it's possible to remove /home/username/ in the output when using zoxide query -i?
$zoxide query -i:
134.9 /home/username/.oh-my-zsh/custom
135.7 /home/username/.local/share/nvim/lazy/friendly-snippet
139.1 /home/username/Documents/books/clipboard
152.1 /home/username/.config/sway/scripts
159.8 /home/username/.local
195.7 /home/username/Documents
212.5 /home/username/repo
220.4 /home/username/.config/tmuxp
227.1 /home/username/Nextcloud/videos
258.6 /home/username/Nextcloud
260.7 /home/username/.config/nvim
301.1 /home/username/.config
307.7 /home/username/.config/sway/config.d
504.9 /home/username/.config/sway
878.6 /home/username/Downloads/test
1071.5 /home/username/.config/ranger
1374.3 /home/username/Videos
> 2827.7 /home/username/Downloads
As you can see, the $HOME prefix is cluttering the output and making it hard to distinguish the output (at least for me).
What I hope to achieve
All of the time, I'm searching inside $HOME. What I'd hope to achieve is the following when using $zoxide query -i:
134.9 .oh-my-zsh/custom
135.7 .local/share/nvim/lazy/friendly-snippet
139.1 Documents/books/clipboard
152.1 .config/sway/scripts
159.8 .local
195.7 Documents
212.5 repo
220.4 .config/tmuxp
227.1 Nextcloud/videos
258.6 Nextcloud
260.7 .config/nvim
301.1 .config
307.7 .config/sway/config.d
504.9 .config/sway
878.6 Downloads/test
1071.5 .config/ranger
1374.3 Videos
> 2827.7 Downloads
That is, hide /home/username/ from the output. I understand that zoxide also includes directories other than $HOME (i.e., /var/lib/flatpak/exports/share/applications as long as I've cd into it before).
If the above (hiding /home/username/ from the output) is not possible, at least replace /home/username/ with ~:
134.9 ~/.oh-my-zsh/custom
135.7 ~/.local/share/nvim/lazy/friendly-snippet
139.1 ~/Documents/books/clipboard
152.1 ~/.config/sway/scripts
159.8 ~/.local
195.7 ~/Documents
212.5 ~/repo
220.4 ~/.config/tmuxp
227.1 ~/Nextcloud/videos
258.6 ~/Nextcloud
260.7 ~/.config/nvim
301.1 ~/.config
307.7 ~/.config/sway/config.d
504.9 ~/.config/sway
878.6 ~/Downloads/test
1071.5 ~/.config/ranger
1374.3 ~/Videos
> 2827.7 ~/Downloads
This avoids the problem of not being able to distinguish between directories other than $HOME.
What I've tried
- I've looked into
_ZO_EXCLUDE_DIRS. But it "Excludes the specified directories from the database." I'd like to excludes the specified directories from the output, not the database. - man fzf but there's no relevant flags.
Any input is much appreciated. Thank you.
Agreed, ~ would be much clearer. I'll look into this.
Hello @ajeetdsouza , hope you're doing well. Any update please?
Hello! I tried the following gpt generated code:
impl Display for DirDisplay<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let home_dir = dirs::home_dir()
.unwrap()
.to_str()
.unwrap()
.to_owned();
let path = self.dir.path.replace(&home_dir, "~");
if let Some(now) = self.now {
let score = self.dir.score(now).clamp(0.0, 9999.0);
write!(f, "{score:>6.1}{}", self.separator)?;
}
write!(f, "{}", path)
}
}
It does shorten the home dir to ~but it crashes when I press Enter.