├── Makefile
├── README.md
├── goto
├── install.sh
└── man_page
└── goto.1
/Makefile:
--------------------------------------------------------------------------------
1 | bold=`tput bold`
2 | normal=`tput sgr0`
3 |
4 | all:
5 | @echo "Run ${bold}'make install'${normal}."
6 |
7 | install:
8 | bash install.sh
9 |
10 | .PHONY: all install
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # goto
2 | Linux Shell 'cd' replacement tool. Kindof like, cd on steroids, with fuzzy file finder and a directory bookmark saver.
3 | License: Standard MIT License.
4 | By: Ankit Vadehra
5 |
6 |
Update:
Due to the awesome people on GitHub and Hackernews, i have come to know of many changes that had to be done. I'm adding a method to Update the script and add "man" page for people who have already installed "goto".
7 | To Update goto:
8 | ~$ wget -O goto "https://raw.githubusercontent.com/ankitvad/goto/master/goto"
9 | ~$ mv goto ~/.local/bin/
10 |
11 | To Add the 'man' page:
12 | ~$ wget -O goto.1 "https://raw.githubusercontent.com/ankitvad/goto/master/man_page/goto.1"
13 | ~$ sudo cp goto.1 /usr/local/share/man/man1/
14 | ~$ sudo mandb
15 | That's about it. You can see the man page by: man goto
16 |
17 | For New users, the normal installation will suffice. Look below for instructions.
18 | Detailed Description: goto | cd on steroids.
19 | ===========
20 | Installation:
21 | To install:
22 | If You have "git" installed
23 | ~$ git clone "https://github.com/ankitvad/goto"
24 | ~$ cd goto
25 | ~$ make install
26 | If "git" is not present
27 | ~$ wget -O goto.zip "https://github.com/ankitvad/goto/archive/master.zip"
28 | ~$ unzip goto.zip
29 | ~$ cd goto-master
30 | ~$ make install
31 |
32 |
--------------------------------------------------------------------------------
/goto:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #GOTO-BASH
3 | #A simple script to save Directory locations so as to make
4 | #moving between directory's easy.
5 | #Also, contains a fuzzy directory finder to make searching for folder
6 | #names easier.
7 | #A replacement for "cd".
8 | #By: Ankit Vadehra
9 | #Contact: ankitvad[at]gmail[dot]com
10 | #URL: http://ankitvad.github.io/
11 | #License: Standard MIT License.
12 |
13 | #Initialise the File to Save all Directory locations
14 | #Saving the Folder into the User folder.
15 | #This is necessary the first time and will
16 | #be omitted after that.
17 |
18 | #This is for bold and normal printing :
19 | bold=`tput bold`
20 | normal=`tput sgr0`
21 |
22 | #The saving directory.
23 | savefile=~/.GOTO/
24 | if [ ! -e "$savefile" ]; then
25 | mkdir $savefile
26 | fi
27 |
28 | number_of_parameter="$#"
29 | first_parameter="$1"
30 | second_parameter="$2"
31 | #Cases depending on the number of Parmeters passed.
32 |
33 |
34 | usage(){
35 | echo -e "${bold}'goto'${normal} is a replacement for the ${bold}cd${normal} tool. It has better functionalities than cd, like a ${bold}FuzzyFinder${normal} and a ${bold}Directory Location Saver${normal}."
36 | echo -e "Usage:\n"
37 | echo -n "${bold}goto -h||-help||h||help"
38 | echo -e "${normal} : Prints the Usage\n"
39 | echo -n "${bold}goto "
40 | echo -e "${normal} : Takes you to the ${bold}\n"
41 | echo -n "${bold}goto s||-s ${normal}"
42 | echo -e "${normal} : Saves the Current Directory location as ${bold}\n"
43 | echo -n "${bold}goto l||-l${normal}"
44 | echo -e " : Lists all the Bookmarks saved.\n"
45 | echo -n "${bold}goto d||-d ${normal}"
46 | echo -e " : Deletes the ${bold} ${normal}saved.\n"
47 | echo -n "${bold}goto p||-p ${normal}"
48 | echo -e " : Prints the GOTO directory for ${bold}\n"
49 | echo -n "${bold}goto f||-f||find||-find ${normal}"
50 | echo -e " : Fuzzy-Finds all the file/folder matching REGEX in the working directory\n"
51 |
52 | }
53 | #To throw to Specific Functions
54 | one_parameter(){
55 | #Passing all possible functions..
56 | if [ "$first_parameter" = "-h" ] || [ "$first_parameter" = "-help" ] || [ "$first_parameter" = "help" ] || [ "$first_parameter" = "h" ] ; then
57 | #Printing the Usage Help.
58 | usage
59 | #For Printing the List
60 | elif [ "$first_parameter" = "l" ] || [ "$first_parameter" = "-l" ] ; then
61 | if [ ! -e "$savefile" ]; then
62 | echo -e "You have not added any directory yet."
63 | mkdir $savefile
64 | usage
65 | elif [ ! "$(ls $savefile)" ]; then
66 | echo -e "You have not added any directory yet."
67 | usage
68 | else
69 | #Reverse the path. Delete everything after / and before .
70 | for file in $savefile*.skt; do
71 | x="$(echo "$file" | rev)"
72 | y=${x%%/*}
73 | x="$(echo -n ${y##*.} | rev)"
74 | echo -n "$x"
75 | echo " : $(cat $file)"
76 | echo -e " "
77 | done
78 | fi
79 | else
80 | #Change the Directory to target.
81 | #here check if shortcut exists
82 | if [ -e "$savefile$first_parameter.skt" ]; then
83 | x="$savefile$first_parameter.skt"
84 | y="$(cat $x)"
85 | cd $y
86 | #If not, just CD to that location.
87 | elif [ -e "$first_parameter" ]; then
88 | cd "$first_parameter"
89 | else
90 | echo -e "The Location/File/Folder $first_parameter does not exist."
91 | fi
92 | fi
93 | }
94 |
95 | two_parameter(){
96 | #For saving.
97 | if [ "$first_parameter" = "s" ] || [ "$first_parameter" = "-s" ] ; then
98 | save_shortcut
99 | elif [ "$first_parameter" = "p" ] || [ "$first_parameter" = "-p" ] ; then
100 | print_shortcut
101 | elif [ "$first_parameter" = "d" ] || [ "$first_parameter" = "-d" ] ; then
102 | delete_shortcut
103 | elif [ "$first_parameter" = "f" ] || [ "$first_parameter" = "-f" ] || [ "$first_parameter" = "find" ] || [ "$first_parameter" = "-find" ] ; then
104 | working_dir_finder
105 | fi
106 | }
107 |
108 | save_shortcut(){
109 | if [ -e "$savefile$second_parameter.skt" ]; then
110 | x="$savefile$second_parameter.skt"
111 | echo -e "Existing Shortcut:"
112 | echo -n "$second_parameter : "
113 | echo -e "$(cat $x)"
114 | echo -e "\nThis Shortcut allready exists. Chose another one or delete the existing one."
115 | else
116 | pwd > "$savefile$second_parameter.skt"
117 | echo -e "Shortcut Created."
118 | fi
119 | }
120 |
121 | print_shortcut(){
122 | if [ ! -e "$savefile$second_parameter.skt" ]; then
123 | echo -e "The Shortcut you're trying to find does not exist."
124 | echo -e "Please see the Shortcut Links for a complete list."
125 | else
126 | x="$savefile$second_parameter.skt"
127 | echo -n "$second_parameter : "
128 | echo -e "$(cat $x)"
129 | fi
130 | }
131 |
132 | delete_shortcut(){
133 | if [ ! -e "$savefile$second_parameter.skt" ]; then
134 | echo -e "The Shortcut you're trying to find does not exist."
135 | echo -e "Please see the Shortcut Links for a complete list."
136 | else
137 | echo -e "Are you sure you want to delete: "
138 | x="$savefile$second_parameter.skt"
139 | echo -n "$second_parameter : "
140 | echo -e "$(cat $x)"
141 | echo -e "(yes/no)"
142 | read choice
143 | if [ "$choice" = "yes" ] || [ "$choice" = "y" ] ; then
144 | rm "$x"
145 | echo -e "Shortcut Deleted."
146 | fi
147 | fi
148 | }
149 |
150 | working_dir_finder(){
151 | #This function is used for finding a particular file in the working directory.
152 | term="$second_parameter"
153 | regex_value="[-_A-Za-z0-9]*"
154 | length=${#term}
155 | x="$regex_value"
156 | for (( i=0; i<$length; i++ )); do
157 | y="$x${term:$i:1}"
158 | x="$y$regex_value"
159 | done
160 | regex_pattern="$x"
161 | #echo -e "\nThe REGEX Pattern is : $regex_pattern"
162 | #i just need: [A-Za-z0-9]* after each literal, or before. no idea.
163 | ls -R $pwd | grep -i $regex_pattern
164 | }
165 |
166 |
167 | case "$number_of_parameter" in
168 | # 0 parameters, ie. general tool definition printing.
169 | 0) usage
170 | ;;
171 | #1-Parameter for: help, list or cd feauture.
172 | 1) one_parameter
173 | ;;
174 | #2-Parameter for: save, print, delete, find and findall
175 | #feauture.
176 | 2) two_parameter
177 | ;;
178 | #More than 2 is wrong, and should throw a usage error.
179 | *) usage
180 | ;;
181 | esac
182 |
183 |
184 |
185 |
--------------------------------------------------------------------------------
/install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #Part of goto: cd replacement tool.
3 | #By: Ankit Vadehra
4 | #Contact: ankitvad[at]gmail[dot[com]
5 | #License: Standard MIT License.
6 | INSTALL=~/.local/bin
7 | BASH_FILE=~/.bashrc
8 | #for those on bash_profile.
9 | BASH_FILE2=~/.bash_profile
10 | bold=`tput bold`
11 | normal=`tput sgr0`
12 | mkdir -p "$INSTALL"
13 | cp goto "$INSTALL"
14 | #For people using .bashrc.
15 | if [ -f "$BASH_FILE" ]; then
16 | echo 'export PATH=$PATH:~/.local/bin/' >> "$BASH_FILE"
17 | echo 'alias goto=". goto"' >> "$BASH_FILE"
18 | echo -e "Added Stuff in .bashrc"
19 | . ~/.bashrc
20 | fi
21 | #Creating new bash_profile file, if doesnt exist. if exists, the appending
22 | #value. Some people on MAC don't use .bashrc.
23 | if [ -f "$BASH_FILE2" ]; then
24 | echo 'export PATH=$PATH:~/.local/bin/' >> "$BASH_FILE2"
25 | echo 'alias goto=". goto"' >> "$BASH_FILE2"
26 | echo -e "Added Stuff in .bash_profile"
27 | . ~/.bash_profile
28 | fi
29 | echo -e "Do you wish to install the 'man' page for goto?"
30 | echo -e "root/sudo privilege might be required? (yes/no)"
31 | read choice
32 | if [ "$choice" = "yes" ] || [ "$choice" = "y" ] ; then
33 | sudo cp "$(pwd)/man_page/goto.1" /usr/share/man/man1/
34 | #This should work. Trying.
35 | sudo cp "$(pwd)/man_page/goto.1" /usr/share/man/
36 | #I was just notified by 'Drew Mills' on Google+ that the command
37 | #'mandb' does not exist for a MAC system. Since, this file
38 | #copies the man-page in the proper location anyways, it seems
39 | #that a MAC system is able to pick up the new man page automatically.
40 | #No Manual 'mandb' required. Hence adding a condition to check for
41 | #'mandb's existence, and then executing it. So, that errors don't creep up.
42 | #Thank's Drew. :)
43 | #Checking for mandb :
44 | if type "mandb" > /dev/null 2>&1; then
45 | sudo mandb
46 | fi
47 | echo -e " "
48 | echo -e "Done. Added man page. To access: 'man goto'"
49 | else
50 | echo -e "man page not installed."
51 | echo -e "To manually install copy '/man_page/goto.1' to the man page location."
52 | fi
53 | exit 0
54 |
--------------------------------------------------------------------------------
/man_page/goto.1:
--------------------------------------------------------------------------------
1 | .\" Manpage for goto.
2 | .\" Contact ankitvad[at]gmail[dot]com, to correct errors or typos.
3 | .TH man 8 "04 January 2014" "1.0" "goto man page"
4 | .SH NAME
5 | \fBgoto\fR \- Linux \fBcd\fR replacement tool with \fBDirectory Bookmark Saving\fR and \fBFuzzy-Finding\fR feautures.
6 | .SH SYNOPSIS
7 | \fBgoto\fR [\fB-h||-help||h||help\fR]
8 | .P
9 | \fBgoto\fR [\fBlocation_address\fR]
10 | .P
11 | \fBgoto\fR [\fBs||-s\fR] [\fBshortcut\fR]
12 | .P
13 | \fBgoto\fR [\fBl||-l\fR]
14 | .P
15 | \fBgoto\fR [\fBd||-d\fR] [\fBshortcut\fR]
16 | .P
17 | \fBgoto\fR [\fBp||-p\fR] [\fBshortcut\fR]
18 | .P
19 | \fBgoto\fR [\fBf||-f||find||-find\fR] [\fBterm\fR]
20 | .SH DESCRIPTION
21 | \fBgoto\fR is a \fBcd\fR replacement tool for shell. It allows saving of directories as shortcuts/bookmarks which makes it easier to jump to the required destination. It also features a fuzzy-finder, which is able to match files in the working directory by REGEX matching. It makes traversing between directories a breeze.
22 | .SH OPTIONS
23 | .P
24 | \fB-h, -help, h, help\fR
25 | .RS 10
26 | Prints the Usage for \fBgoto\fR.
27 | .RE
28 | .P
29 | \fBlocation_address\fR
30 | .RS 10
31 | Checks whether \fBlocation_address\fR is a shortcut or not. If it is, then it goes to the directory location pointed by that shortcut. If a shortcut does not exist, then it replicates \fBcd\fR's behavious and switches to the location contained in \fBlocation_address\fR.
32 | .RE
33 | .P
34 | \fBl, -l\fR
35 | .RS 10
36 | Lists all the Bookmarks saved with the directories they point to.
37 | .RE
38 | .P
39 | \fBd, -d\fR [\fBshortcut\fR]
40 | .RS 10
41 | Deletes the bookmark passed in [\fBshortcut\fR].
42 | .RE
43 | .P
44 | \fBp, -p\fR [\fBshortcut\fR]
45 | .RS 10
46 | Prints the GOTO directory for [\fBshortcut\fR] passed.
47 | .RE
48 | .P
49 | \fBf, -f, find, -find\fR [\fBterm\fR]
50 | .RS 10
51 | Performs fuzzy-search for the \fBterm\fR passed through REGEX pattern matching.
52 | .RE
53 | .SH BUGS
54 | No known bugs. Program development takes place at: "\fBhttps://github.com/ankitvad/goto\fR" .
55 | .SH AUTHOR
56 | \fBAnkit Vadehra\fR \- (\fBankitvad\fR[\fBat\fR]\fBgmail\fR[\fBdot\fR]\fBcom\fR)
57 | .P
58 | \fBhttp://ankitvad.github.io/\fR
59 |
--------------------------------------------------------------------------------