1

Currently, 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?

Maths Wizzard
  • 221
  • 1
  • 6
  • 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?](https://meta.stackoverflow.com/q/284236/4518341) 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 [ask]. – wjandrea Jul 09 '22 at 17:26
  • Possible duplicate: [Recursively look for files with a specific extension](/q/5927369/4518341) – wjandrea Jul 09 '22 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. – Maths Wizzard Jul 09 '22 at 17:30

1 Answers1

2

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

chosen=$(find ~/UniNotes -name '*.tex' | rofi -dmenu -i "Test" )
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • 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. – Maths Wizzard Jul 09 '22 at 17:24
  • 1
    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'` – glenn jackman Jul 09 '22 at 17:27
  • 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? – Maths Wizzard Jul 09 '22 at 18:07
  • Nope. You'll have to read the documentation for rofi to ensure it's reading options separated by newlines not separated by _whitespace_. – glenn jackman Jul 09 '22 at 22:14
  • 1
    And the full path problem, make sure you change the 1st argument to the find command – glenn jackman Jul 09 '22 at 22:15