代码拉取完成,页面将自动刷新
同步操作将从 _KK/useful-scripts 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/bin/bash
# @Function
# Run command and put output to system clipper.
#
# @Usage
# $ c echo "hello world!"
# $ echo "hello world!" | c
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/master/docs/shell.md#-c
# @author Jerry Lee (oldratlee at gmail dot com)
set -e
set -o pipefail
readonly PROG="`basename "$0"`"
usage() {
local -r exit_code="$1"
shift
[ -n "$exit_code" -a "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout
(( $# > 0 )) && { echo "$@"; echo; } > $out
> $out cat <<EOF
Usage: ${PROG} [OPTION]... [command [command_args ...]]
Run command and put output to system clipper.
If no command is specified, read from stdin(pipe).
Example:
${PROG} echo "hello world!"
${PROG} grep -i 'hello world' menu.h main.c
set | ${PROG}
${PROG} -q < ~/.ssh/id_rsa.pub
Options:
-k, --keep-eol do not trim new line at end of file
-q, --quiet suppress all normal output, default is false
-h, --help display this help and exit
EOF
exit $exit_code
}
################################################################################
# parse options
################################################################################
quiet=false
eol=-n
while [ $# -gt 0 ]; do
case "$1" in
-k|--keep-eol)
eol=
shift
;;
-q|--quiet)
quiet=true
shift
;;
-h|--help)
usage
;;
--)
shift
args=("${args[@]}" "$@")
break
;;
-*)
usage 2 "${PROG}: unrecognized option '$1'"
;;
*)
# if not option, treat all follow args as command
args=("${args[@]}" "$@")
break
;;
esac
done
################################################################################
# biz logic
################################################################################
copy() {
case "`uname`" in
Darwin*)
pbcopy ;;
CYGWIN*|MINGW*)
clip ;;
*)
xsel -b ;;
esac
}
teeAndCopy() {
$quiet && local out=/dev/null || local out=/dev/stdout
tee >(
content="$(cat)"
echo $eol "$content" | copy
) > $out
}
if [ ${#args[@]} -eq 0 ]; then
teeAndCopy
else
"${args[@]}" | teeAndCopy
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。