2

I have a "sandbox" folder on my 13.10 PC, which I use for anything along the lines of "testing", or if I'm updating a piece of code and want it to be completely separate from everything else. In order to have some amount of order for this, I have this split into subfolders, in the following structure:

/data/Work/sandbox/mmyy/ddmmyy

(i.e. today's folder is /data/Work/sandbox/0214/260214.)

In order to be able to switch to this directory quickly, I set up my .bashrc so as to assign an environment variable, $TODAYSAND, which changes daily and points to the correct folder, using the date command:

TODAYSAND="/data/Work/sandbox/`date +%m%y/%d%m%y`"

This works fine in shells, so I've removed this line from .bashrc and added it to my profile.d in a new script, /etc/profile.d/sandbox.sh. It still sources correctly, and in terminals I can still cd $TODAYSAND without any issues at all.

I would now like to set a bookmark in Nautilus that points to this folder and changes dynamically in the same way, so that I don't have to track down the latest one every time. However, I can't get it to even accept $TODAYSAND as a folder name. If I type it in the top bar (by typing a / to let me input a path rather than searching), it tries to go to a non-existent file literally named /$TODAYSAND and gives me an error saying that this doesn't exist. Similarly, if I make a bookmark pointing to $TODAYSAND, it a) creates it with the same icon as if I had told it to bookmark a network location, and b) crashes out of Nautilus instantly when I click on it.

How can I go about making Nautilus accept this variable as a valid filepath?

4
  • I'm not sure how to use an environment variable in nautilus, but why not just have a symlink in your home directory to the daily sandbox? You can either use your bashrc on login (if you log in every day), or a cron job to update the symlink each day.
    – chronitis
    Feb 26, 2014 at 15:35
  • @chronitis intriguing idea, hadn't thought of that. The daily scheduling would work (I do use a terminal almost every time I log in, but once per day would be preferable). cron is one of those things that I can't remember ever having used, though. How would I go about doing this?
    – Jez W
    Feb 26, 2014 at 16:34
  • Without knowing if it is at all possible to have Nautilus expand an environment variable, I just wanted to add a remark: Environment variables set via .bashrc are only available in the bash shell, not in the graphical environment. However, when you switched to creating it via a /etc/profile.d/*.sh file, that changed. More info in help.ubuntu.com/community/… Feb 26, 2014 at 21:46
  • @Gunnar Thanks for the remark - indeed, this difference was the reason why I moved the definition from .bashrc to profile.d in the first place. Trying it in a shell was just a way of making sure it was still being sourced properly (and in fact, the kate editor manages to expand it as well when started from the graphical interface, so it's certainly worked)
    – Jez W
    Feb 27, 2014 at 10:18

1 Answer 1

1

I did not found a way to pass the Environment variables to Nautilus.

Here is the answer "How to update a bookmark dynamically?"

In Ubuntu 12.04 Nautilus stores bookmarks in ~/.gtk-bookmarks in the following format

file:///home/username/Documents
....
file:///path/to/0214/260214

You can use a small bash function to change the last line to

file:///path/to/0214/270214

It will change the bookmark dynamically. Here is the script

updt_sand_box(){
if [ -d /path/to/"$(date +%m%y)"/"$(date +%d%m%y)" ]; then
    sed -i "s#$(date --date yesterday "+%d%m%y")#$(date +%d%m%y)#" ~/.gtk-bookmarks
else
    zenity --info --text="/path/to/$(date +%m%y)/$(date +%d%m%y) does not exist"
fi
}

Put the above function in ~/.bashrc and source it,

. ~/.bashrc

To updte the sandbox bookmark enter in your terminal

updt_sand_box

You can use the above script in various way. You can create a cronjob (use proper DISPLY variable) or put it in ~/.bashrc or anywhere so that it can be run.

Most probably Newer Ubuntu stores bookmarks in ~/.config/gtk-3.0/bookmarks, you need to modify the script accordingly.

Replace ~/.gtk-bookmarks with ~/.config/gtk-3.0/bookmarks in the above script.

6
  • @JezW isn't it what you are looking for?
    – sourav c.
    Feb 28, 2014 at 18:26
  • Thanks for this, being able to modify the bookmarks progamatically is quite useful. Is the way bookmarks are formatted and stored documented somewhere or is subject to change on any version upgrade ?
    – pllee
    Mar 6, 2014 at 19:49
  • I was wondering if this info is in a public api or if this is just how it is working currently. If it is not public Ubuntu can store bookmarks in a different location or format for the next release without providing a migration guide.
    – pllee
    Mar 7, 2014 at 16:01
  • I misunderstood your query before. Most Linux stores bookmarks in ~/.gtk-bookmarks, newer Ubuntus are using ~/.config/gtk-3.0/bookmarks. Can't say what will be in future but I don't think developers will think to modify an established and well known feature. I saw use of these files to edit bookmarks on web including AU. I will inform you if I found a documentation.
    – sourav c.
    Mar 7, 2014 at 20:45
  • If you store file:///path/to/folder the bookmark will be shown as folder. If you put file:///path/to/folder xyz123 the same folder will be shown as bookmark with name xyz123.
    – sourav c.
    Mar 7, 2014 at 20:50

You must log in to answer this question.

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