2

Unfortunately the bookmark pane in Nautilus offers no sub-folders and on my system only about 40 bookmarks can be visible at the same time.

The bookmarks are stored in in a pre-set file ~/.config/gtk-3.0/bookmarks. Presently I use different bookmark files for different projects something that really is a hassle.

Any tip on howto improve on this is appreciated.

Is there any possibility to use different bookmark files for different projects on Nautilus startup or may we expect sub-folders in the near future?

1

I found that Nautilus bookmarks are dynamically changing when the content of the file ~/.config/gtk-3.0/bookmarks is changed. So my suggestion is the following script, that could be bind to a custom keyboard shortcut. Here is ho it works:

enter image description here

  • Create executable file, called nautilus-bookmarks-manager and located in the directory /usr/local/bin to be accessible as shell command (or use different name and location):

    sudo touch /usr/local/bin/nautilus-bookmarks-manager
    sudo chmod +x /usr/local/bin/nautilus-bookmarks-manager
    sudo nano /usr/local/bin/nautilus-bookmarks-manager
    
  • Create Custom keyboard shortcut where the command should be:

    /usr/local/bin/nautilus-bookmarks-manager
    

The script content is:

#!/bin/bash

# Initial variables; the last underscore in $PROFILE_NAME_TEMPLATE is important
BOOKMARKS_DIR="$HOME/.config/gtk-3.0"
BOOKMARKS="$BOOKMARKS_DIR/bookmarks"
PROFILES_DIR="$BOOKMARKS_DIR/bookmarks_profiles"
PROFILE_NAME_TEMPLATE="$PROFILES_DIR/bookmarks_profile_"

# If the profiles directory doesn't exist create it,
# otherwise renumber the existing profiles in case some of them were deleted
[[ ! -d $PROFILES_DIR ]] && mkdir -p "$PROFILES_DIR" || rename 's/[0-9]*$/our $i; sprintf("%d", 1+$i++)/e' "$PROFILES_DIR/"*

# Get the list of the profiles as an array,
# the expression `[[ -z ${PROFILES[@]##*\*} ]]` means `if the directory is empty` or not empty when there is a `!`
PROFILES=("$BOOKMARKS_DIR/bookmarks_profiles/"*)

main() {
        # Compare the current profile to each existing profile in $PROFILES and find the $CURRENT_PROFILE if it exists
        for profile in "${PROFILES[@]}"; do cmp -s "$BOOKMARKS" "$profile" && CURRENT_PROFILE="$profile"; done

        # Get the number of the current profile
        CURRENT_PROFILE_NUMBER="${CURRENT_PROFILE##*_}"

        # If the $CURRENT_PROFILE doesn't exist in the list of profiles and the directory is epty: $NEW_PROFILE_NUMBER = 1
        # If it doesn't exist and the directory is not epty: $NEW_PROFILE_NUMBER = ( number of the profiles + 1 )
        # If this is the last profile from the list the next profile number is 1: $NEW_PROFILE_NUMBER = 1
        # In all other case increment the $CURRENT_PROFILE_NUMBER by 1
        if   [[ -z ${CURRENT_PROFILE+x} && -z ${PROFILES[@]##*\*} ]]; then
                NEW_PROFILE_NUMBER=1
        elif [[ -z ${CURRENT_PROFILE+x} && ! -z ${PROFILES[@]##*\*} ]]; then
                NEW_PROFILE_NUMBER=$(( ${#PROFILES[@]} + 1 ))
        elif [[ $CURRENT_PROFILE_NUMBER -eq ${PROFILES[-1]##*_} ]]; then
                NEW_PROFILE_NUMBER=1
        else
                NEW_PROFILE_NUMBER=$(( CURRENT_PROFILE_NUMBER + 1 ))
        fi

        # If the current profile doesn't exist in the list add it, else just switch to the next profile
        if   [[ -z ${CURRENT_PROFILE+x} ]]; then
                cp "${BOOKMARKS}" "${PROFILE_NAME_TEMPLATE}${NEW_PROFILE_NUMBER}"
                echo "Profile ${NEW_PROFILE_NUMBER} is CREATED"
        else
                cp "${PROFILE_NAME_TEMPLATE}${NEW_PROFILE_NUMBER}" "${BOOKMARKS}"
                echo "Profile ${NEW_PROFILE_NUMBER} is ACTIVATED"
        fi
}

killall notify-osd >/dev/null 2>&1  # Kill all notify-send messages
notify-send "$(main 2>&1)"          # Call the `main` function and output all messages through `notify-send`

The script will store each new profile in the directory ~/.config/gtk-3.0/bookmarks_profiles. If this directory doesn't exist it will be created. Otherwise the script will try to renimber the existing profiles in case you have removed some of them. This leads two cases:

  • When you want to delete certain profile, first you should activate some other profile;
  • When you want to move certain profile to the end of the list, activate it, then delete it and execute the script.

Next. The script will compare the file ~/.config/gtk-3.0/bookmarks with each file in ~/.config/gtk-3.0/bookmarks_profiles. If coincidence is found the script will switch to the next profile. If there is not coincidence a new profile will be created.

A more advanced version of the script could use named (instead numbered) profiles and and some tool like zenity to get the names of the new profiles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.