3
votes
How can I make "whereis" automatically open the file on Nvim when it is the only result?
EDIT: SOLVED
It looks like it was much simple than I thought and someone solved it on Reddit already. I won't delete, just leave the link if someone is interested.
Runtime Environment
- OS: MX Linux 18
- Result of Y: 4.19.0-5-amd64
- dotfiles
- i3 version: 4.13
- ~/.config/i3
- GNU Emacs: 27.0.50
- ~/.emacs.d
Issue
Sometimes I use "whereis" (aliased for "wh", but it doesn't make any difference...) for my own scripts.
I usually copy their paths manually (using tmux) and paste to the command line resulting in something like this:
nvim /home/my_username/my_scripts_folder/my_script
Could I make that into a single command?
Thanks in advance!
I'll have to edit this (on mobile) and confirm it but something like:
Inside .bashrc
alias wh=~/bin/nvim-whereis
inside nvim-whereis
#/use/bin/env bash
Output=$(Whereis "$@")
[[ $(Echo $output | cut -d: -f2 | xargs -n1 | wc -l) -eq 1 ]] && nvim $(echo $output | cut -d: -f2) || echo $(output)
99% sure this won't work as is. Might be capturing random white space and what not, but maybe this gives you an idea of what you can do.
The alias in the Bash just sets up a shortcut. You could just add ~/bin to you path, then you don't need the alias and just rename the script to something shorter
Have you seen the answer in the SOLVED link? I now have a script with the following content, which seems to be doing the job:
I just realized I forgot to put the link. Fixed now. Anyway: here it is.
Oh nice, way cleaner.
Someone else suggested an even cleaner solution: