#!/usr/bin/env ruby # All Jumper code is Copyright 2011 by Pascal Ryckmans . # 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, version 2 of the License. # 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 . #The file to add you bookmark to $path = File.expand_path("~/.bashrc") #Get variables out of command $info = ARGV[0] $info1 = ARGV[1] #Check if bookmark file exists before doing anything bashchecker = File.exist?($path) #If .bashrc exists if bashchecker == true #Command handler #Check if there's info given, also check if the bookmarked dir exists bmchecker = File.directory?($info1) if ((defined?($info)) && (defined?($info1)) && ($info != nil) && ($info1 != nil) && (bmchecker == true)) $name = $info.downcase puts "Bookmark #{$name} with destination #{$info1} has been added to your bookmarks.\nYou can access your bookmark with the command jump-#{$name}.\nPlease note: If you are running a shell you should reload your .bashrc file (source ~/.bashrc).\nIf you want a list of all your bookmarks just run the command alias." open( $path, "a" ) do |bookmarks| bookmarks.puts "alias jump-#{$name}=\"cd #{$info1}\"\n" end else puts "Wrong command. The format of the command needs to be: jump BOOKMARK_NAME BOOKMARK_DESTINATION.\n Or your destination does not exist.\n" end #If the file does not exist: create it else File.open( $path, "w" ) File.chmod 0644, $path puts "Your .bashrc-file did not existed. The program created it for you, please run your command again." end