1

I use Linux and want to use a program named Trelby to open directly the latest saved file.

The latest saved file is stored in the seventh line of the file /home/me/.trelby/state, which looks like this:

PositionX:0
PositionY:0
Width:1366
Height:736
ViewMode:1
Files:5
Files/1:/home/me/writing/text-1.trelby
Files/2:/home/me/writing/text-2.trelby
Files/3:/home/me/writing/text-3.trelby
Files/4:/home/me/writing/text-4.trelby
Files/5:/home/me/writing/text-5.trelby

Hence the command I want to execute should be:

trelby /home/me/writing/text-1.trelby

What command could I use to read the 'state' file and have the portion /home/me/writing/text-1.trelbyappended to the Trelby command?

1
  • Please edit your question: What OS are you in? I assume macOS? Or Linux? Oct 22, 2021 at 23:31

2 Answers 2

2

In general, avoid relying too much on something as incidental as the line number in which you find the information. In its next version, maybe trelby will add a line with some new saved setting and your command will be broken.

The syntax of the file you give is rather transparent that the path of the latest file is prepended by "Files/1": use this rather than the line number.

In bash, you can use:

trelby $(awk -F: '{if ($1=="Files/1") {print $2}}' ${HOME}/.trelby/state)
1
  • Those are all good points and your solution worked just fine.. Oct 23, 2021 at 16:12
1

There might be a more elegant or effective solution, but this worked:

trelby $(head -7 /home/me/.trelby/state | tail -1 | cut -c9-100)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .