aboutsummaryrefslogtreecommitdiff
path: root/catcode
blob: fb3b99d88c0ef9bbfa7db0edf49ce8c2f9cbb397 (plain)
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
#!/usr/bin/env bash
#
# Display the source of a script.
#

# Parameters
BASENAME="`basename $0`"
COMMAND="$1"
PAGER="$2"

# Check
if [ -z "$COMMAND" ]; then
  echo "usage: $BASENAME <command>"
elif [ ! -e "$COMMAND" ]; then
  COMMAND="`which $COMMAND 2> /dev/null`"

  if [ -z "$COMMAND" ]; then
    echo "$BASENAME: cannot find command"
    exit 1
  fi
fi

# Shebang checker
if head -1 $COMMAND | grep -q '#!'; then
  if [ -z "$PAGER" ]; then
    cat $COMMAND
  elif [ "$PAGER" == "less" ]; then
    less $COMMAND
  fi
fi