#!/bin/sh # # Script: Open Relative Folder on Current Disk # (Landmark Template) # # Version 1.0 # # by Apollia of Astroblahhh.Com. http://astroblahhh.com/ # # # Mostly completed July 25, 2014. Polished on August 16 and 25, 2014. # # Released August 27, 2014. # # # Definitely works in: # # Lucid Puppy Linux 5.2.8 version 004 # # Lighthouse 64 Puppy Linux 6.02 Beta 2 # # #------------------------------------------------------------------------------ # # A script that makes it so you can easily open a folder on the same # disk as this script, even if the disk containing that folder and this # script gets mounted at a different than usual mountpoint. # # I call these shortcuts "landmarks" (partly inspired by Second Life). # I keep most of them in a "Landmarks" folder at the root level of many # of my disks. # #------------------------------------------------------------------------------ # # # Under the GNU General Public License v3.0. # # Copyright (C) 2014 Apollia # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # # Contact info: http://astroblahhh.com/contact-apollia.shtml # # ---- ####################################################################### # # Some stuff you can change # relative_path_to_folder_to_open="/"; # Remove the /[mountpoint parentdir]/[diskname]/ parts from the beginning of the # folder path you want this script to open, and leave the rest. # # Doesn't matter whether or not the path has a slash at the beginning. # # The mountpoint parentdir will probably be either /mnt/ (in Lucid # Puppy 5.2.8 version 004) or /media/ (in Lighthouse 64 Puppy 6.02 Beta). # # # Example non-relative path: # # /mnt/truecrypt44/Folder of Stuff/Even More Stuff # # # Path to use in relative_path_to_folder_to_open: # # "Folder of Stuff/Even More Stuff" file_manager_shell_command_to_use="rox"; # # # End of Some stuff you can change # # Below this point, nothing else in this script needs to be changed. # ####################################################################### ########################################## # # # Start of function # # # Escape_Single_Quotes_for_Bash_and_Enclose_in_Single_Quotes() # # Escape_Single_Quotes_for_Bash_and_Enclose_in_Single_Quotes() { local quotes_escaped quotes_escaped=$(echo "$1" | sed -e "s/'/'\"'\"'/g") echo "'$quotes_escaped'" } # # # End of function # # Escape_Single_Quotes_for_Bash_and_Enclose_in_Single_Quotes() # ########################################################### ########################################################## # # Now, we set a bunch of variables related to the script's # path and filename. # Get_Script_Path_and_Filename() { THIS_SCRIPT_FILE_NAME="$(basename "${BASH_SOURCE[0]}" )" THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" full_path_to_this_script="$THIS_SCRIPT_DIR/$THIS_SCRIPT_FILE_NAME" escaped_enclosed_full_path_to_this_script=$(Escape_Single_Quotes_for_Bash_and_Enclose_in_Single_Quotes "$full_path_to_this_script") } Get_Script_Path_and_Filename ########################################################## # # Then, we announce this script's name and path. # Announce_Script_Now_Running() { echo -e "\n\n*(*)*\n\nBash Script Now Running:\n" echo " $THIS_SCRIPT_FILE_NAME Full path: $full_path_to_this_script" } Announce_Script_Now_Running ########################################################## # # Next, we find out the disk this script is on, and # name of the mountpoint parentdir. # # The mountpoint parentdir is /mnt/ in Lucid Puppy 5.2.8 version 004, # and /media/ in Lighthouse 64 Puppy 6.02 Beta 2. Get_Disk_and_Mountpoint_Parentdir_from_Path() { local this_path=$1 ########################################################## # # Next, we use the "read" command to make an array # containing the disk name and the mountpoint parentdir. IFS="/" # Sets the delimiter for the read command. read -a pathparts this_path <<< "$this_path" mountpoint_parentdir="${pathparts[1]}" disk="${pathparts[2]}" #echo -n " mountpoint parentdir $mountpoint_parentdir disk $disk" } Get_Disk_and_Mountpoint_Parentdir_from_Path "$THIS_SCRIPT_DIR" ########################################################## # # Now that we know the disk this script is on, # and the mountpoint parentdir the disk is in, # we can build the full path to the folder to open. # # full_path_to_folder_to_open="/$mountpoint_parentdir/$disk/$relative_path_to_folder_to_open" escaped_full_path_to_folder_to_open=$(Escape_Single_Quotes_for_Bash_and_Enclose_in_Single_Quotes "$full_path_to_folder_to_open") command_line="$file_manager_shell_command_to_use $escaped_full_path_to_folder_to_open" echo -e "\n\n# $command_line" eval "$command_line" # End of script. # ############################