-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjman
executable file
·48 lines (40 loc) · 973 Bytes
/
jman
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
#!/bin/bash
# jman
# Sunday May 11, 2008
# Author: Joseph Pecoraro
# Email: joepeck02@gmail.com
# Version: 1.0
# Variables/States
outputType=cat
joemanDir="`echo $HOME`/bin/.joeman/"
# Usage string
usage="usage:`basename $0` [-l] progName\n\n\t-l\t\toutput with /usr/bin/less\n\tprogName\tEx. ruby, tr, awk, grep, ...\n"
# Bad number of arguments
if [[ $# -eq 0 ]] || [[ $# -gt 2 ]]; then
echo -e $usage
exit 1
fi
# If two params the first should be -c, ingore otherwise
if [[ $# -eq 2 ]]; then
if [[ "-l" == "$1" ]]; then
outputType=less
fi
shift
fi
# Ensure filename doesn't every have "../"
if [[ "$1" =~ / ]]; then
echo "Filename cannot contain '/'"
exit 1
fi
# Check for the existence of the filename
path="$joemanDir$1"
if [[ ! -e $path ]]; then
echo "$1: File does not exist."
exit 1
fi
# Print out the file
# $outputType is an element of {less, cat}
# $path is the full path to the joeman file
eval "$outputType $path"
# Successful
exit 0