Created
June 6, 2017 10:23
-
-
Save aheadlead/54b23f5868a57f896bd3a5b5a13febdf to your computer and use it in GitHub Desktop.
ubuntu.bash_profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ssh_tunnel_to_jx { | |
ssh -C -N -g -L 20569:$1:$2 pi | |
} | |
function ssh_tunnel { | |
ssh -C -N -g -L 23333:$1:$2 $3 | |
} | |
# 让费时命令执行完推送到 Telegram | |
# http://dlifep.com/2017/05/24/让费时命令执行完推送到-Telegram/ | |
# 卸载?删除下面这段代码即可 | |
function _TGPN_precommand_cbk() { | |
[[ -z "$_TGPN_AT_PROMPT" ]] && return | |
unset _TGPN_AT_PROMPT | |
_TGPN_CMD="$BASH_COMMAND" | |
_TGPN_TELEGRAM_NOTIFY_START_TIME=$(date +%s) | |
} | |
trap '_TGPN_precommand_cbk' DEBUG | |
_TGPN_FIRST_PROMPT=1 | |
function _TGPN_postcommand_cbk() { | |
local retcode=$? | |
_TGPN_AT_PROMPT=1 | |
[[ -n "$_TGPN_FIRST_PROMPT" ]] && { | |
unset _TGPN_FIRST_PROMPT | |
return | |
} | |
local now=$(date +%s) | |
local difference=$(( $now - ${_TGPN_TELEGRAM_NOTIFY_START_TIME:-0} )) | |
_TGPN_THRESHOLD=1 | |
_TGPN_IGNORE=$(cat <<EOF | |
^adb shell | |
^vi | |
^nano | |
^ssh | |
^man | |
^ftp | |
EOF | |
) | |
[[ -z $DISABLE_TELEGRAM_NOTIFICATION ]] && | |
[[ $difference -gt $_TGPN_THRESHOLD ]] && { | |
for pattern in $_TGPN_IGNORE; do | |
echo $_TGPN_CMD | grep -qE $pattern && return | |
done | |
echo "发现了上条命令执行了很久,推送执行完毕信息到 Telegram"; | |
echo $_TGPN_CMD | |
telegram-send "✅$retcode|$_TGPN_CMD" & | |
} | |
} | |
PROMPT_COMMAND="_TGPN_postcommand_cbk" | |
function disable_telegram_notification { | |
DISABLE_TELEGRAM_NOTIFICATION="arbitrary-string" | |
echo "执行很久的命令暂时不会推送到 Telegram 了" | |
} | |
function enable_telegram_notification { | |
unset DISABLE_TELEGRAM_NOTIFICATION | |
echo "执行很久的命令会推送到 Telegram !" | |
} | |
# end of 让费时命令执行完推送到 Telegram | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment