1

I am using the following script for a search bar that opens my notes:

#! /bin/sh cd ~/UniNotes chosen=$(printf '%s\n' * | rofi -dmenu -i "Test" ) cd $chosen/Notes alacritty -e vim $chosen.tex 

This works because my notes follow the template

UniNotes/Subject1/Notes/Subject1.tex 

This set up is quite primitive because it only allows for single tex files to be identified in each folder.

I would like to have a script that lists me all of the tex files from uninotes in rofi. Then I want to select a given tex file and open it with alacrity and vim.

My biggest issue seems to be to somehow preserve the location of a file when it is listed.

Could someone help me with the script?

3
  • I'm not following. Are you saying you have some notes that don't follow that template? Also, is that template even correct? The code seems to include Notes/ in the path (i.e. ~/UniNotes/Subject1/Notes/Subject1.tex). In any case, please read Why is "Can someone help me?" not an actual question? You need to ask a specific question for it to be on-topic here, like maybe "How can I find all .tex files in a folder and subfolders?" For more tips, see How to Ask. Commented Jul 9, 2022 at 17:26
  • Possible duplicate: Recursively look for files with a specific extension Commented Jul 9, 2022 at 17:30
  • 1
    You are right! I had a typo in the directory. Also, yes, some times I have tex files that I want to open that do not follow the template. Say that I have test.tex in UniNotes/Subject1/Notes. I can't open it with that script. Apologies for not writing the question clearer. Commented Jul 9, 2022 at 17:30

1 Answer 1

3

Without knowing what rofi is, maybe you want find instead of printf?

chosen=$(find ~/UniNotes -name '*.tex' | rofi -dmenu -i "Test" ) 
Sign up to request clarification or add additional context in comments.

5 Comments

Hi, thanks for the response. Rofi basically displays all of the options and lets me chose. So the chosen variable is what I have chosen from the list. What you have written works great, however it displays the whole location when I choose the file. Do you know how one could adjust it so that only the name of the file is displayed whilst simultaneously having an associated location that I can store? If some of this does not make sense please let me know and I will elaborate.
By "whole location" do you "full path"? You can do cd ~/UniNotes like in your question and then start finding in the current directory find . -name '*.tex'
I think this is a rofi issue, it dislays the full path regardless of if I had cd ~/UniNotes before hand. However I have found a more serous issue. I just realised that the script does not work with directories that have two words in their name. For example, selecting UniNotes/Fun\ Maths/Complex\ Analysis/Complex\ Analysis.tex makes a file in UniNotes called "Fun". However, when I try to select UniNotes/Probability/Notes/20.tex it works as expected. Do you have any idea how to fix that?
Nope. You'll have to read the documentation for rofi to ensure it's reading options separated by newlines not separated by whitespace.
And the full path problem, make sure you change the 1st argument to the find command

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.