-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmark
More file actions
executable file
·80 lines (70 loc) · 1.86 KB
/
mark
File metadata and controls
executable file
·80 lines (70 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
# mark - Minimalistic path bookmarks for Bourne shell
# author: Piotr Figiel <figiel+github@gmail.com>.
# This work is licensed under a Creative Commons Attribution 3.0 Unported
# License. http://creativecommons.org/licenses/by/3.0/deed.en_US
#
# Setup (valid for bash):
#
# 1. Make `mark` available in path, e.g. put it to ~/bin
# 2. Add following line to your ~/.bashrc file (omit #)
#
# go() { cd `mark get $*`; }
#
# Usage (basic):
#
# mark <name> - creates or updates bookmark for current directory
# go <name> - changes the current directory to bookmarked one
#
# Usage (advanced):
#
# mark get <name> - returns the path saved under bookmark
# mark set <name> - creates or updates bookmark
# mark clear <name> - deletes the bookmark
# mark list - prints list of all saved bookmarks
#
# Example:
#
# user@mamba ~/github/ftools $ mark test
# user@mamba ~/github/ftools $ cd
# user@mamba ~ $ go test
# user@mamba ~/github/ftools $
#
# Hints:
#
# - bookmarks are stored persistently in your ~/.mark.db
# - you don't have to provide full name of the bookmark when using 'go', first
# few letters are fine
#
use Cwd;
dbmopen(%mark_db, $ENV{"HOME"} . "/.mark.db", 0666);
my $db = \%mark_db;
my $cmd = shift @ARGV;
my $args = join " ", @ARGV;
if ( $cmd eq "set" ) {
$db->{$args} = getcwd if length $args;
}
elsif ( $cmd eq "list" ) {
foreach my $key ( keys %$db ) {
print "[$key] = " . ( $db->{$key} ) . "\n";
}
}
elsif ( $cmd eq "get" ) {
if ( defined $args && defined $db->{$args} ) {
print $db->{$args};
}
elsif ( length $args ) {
foreach my $key ( keys %$db ) {
if ( $key =~ /^$args/ ) {
print $db->{$key};
exit 0;
}
}
}
}
elsif ( $cmd eq "clear" ) {
delete $db->{$args};
}
elsif ( length $cmd ) {
$db->{$cmd} = getcwd;
}