-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various fixes to portable-screencap #5
Changes from all commits
fcd55a5
0d056c0
39b1d35
e475932
9ffe52c
1f2cb5f
e213088
86c84f3
4d21048
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
set -o pipefail | ||
USAGE="usage: $0 - take a screenshot and output to stdout, portably" | ||
|
||
usage() { | ||
echo "$0 - take a screenshot and output to stdout, portably" | ||
echo "$USAGE" | ||
exit 0 | ||
} | ||
|
||
die() { | ||
echo >&2 "error: $@" | ||
exit 1 | ||
} | ||
|
||
# get user options | ||
while [ $# -gt 0 ]; do | ||
# get options | ||
arg="$1" | ||
shift | ||
|
||
case "$arg" in | ||
-h) usage ;; | ||
--help) usage ;; | ||
-h|--help) usage ;; | ||
--*) | ||
die "unrecognised option: '$arg'\n$usage" ;; | ||
die "unrecognised option: '$arg'\n$USAGE" ;; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whoops copy-paste fail on my part |
||
*) | ||
die "unrecognised argument" ;; | ||
die "$0 accepts no arguments\n$USAGE" ;; | ||
esac | ||
done | ||
|
||
die() { | ||
echo >&2 "error: $@" | ||
exit 1 | ||
} | ||
|
||
darwin_screencap() { | ||
screencapture -i "$1" | ||
} | ||
|
||
linux_screencap() { | ||
if [ `which import` ]; then | ||
if type import >/dev/null | ||
then | ||
import "$1" | ||
elif [ `which shutter` ]; then | ||
elif type shutter >/dev/null | ||
then | ||
shutter -e -o "$1" | ||
elif [ `which scrot` ]; then | ||
elif type scrot >/dev/null | ||
then | ||
scrot "$1" | ||
else | ||
die "cannot find a supported screen capture tool | ||
|
@@ -50,15 +51,15 @@ please install a supported one: | |
} | ||
|
||
all_screencap() { | ||
case `uname` in | ||
Darwin) darwin_screencap $1 ;; | ||
Linux) linux_screencap $1 ;; | ||
*) die "screencap not implemented for "`uname` ;; | ||
case $(uname) in | ||
Darwin) darwin_screencap "$1" ;; | ||
Linux) linux_screencap "$1" ;; | ||
*) die "screencap not implemented for $(uname)" ;; | ||
esac | ||
} | ||
|
||
date=$(date +"%Y-%m-%dT%H:%M:%SZ") | ||
fpath=$(mktemp /tmp/screencap.$date.XXXXXX.png) | ||
all_screencap $fpath | ||
cat "$fpath" | ||
rm "$fpath" || true | ||
fpath=$(mktemp "/tmp/screencap.$date.XXXXXX.png") | ||
all_screencap "$fpath" || die "capture failed" | ||
echo "Capture is in '$fpath'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i want this script to output the file to stdout. storing in files makes other things (like chaining operations) harder. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok sorry about that. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i recall needing
set -o pipefail
for something. may have been in theipfs-screencap
script.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes something like
false | true
fail though it succeeds by default:But as I said in chriscool@fcd55a5 it is not portable as dash, which is the default /bin/sh on Ubuntu, doesn't know about it: