关键词:
#!/bin/bash
# dontforget
#
# A stupid script for short term reminders in bash
#
# Arguments just need to contain a number and a bunch of words.
#
# The number can be anywhere in the arguments, but there shouldn't
# be any other numeric digits.
#
# If the number has h, m, or s immediately after it (no space), it will
# be interpreted as hours, minutes, or seconds. The default assumption
# is minutes.
#
# Save the script as `dontforget` in your path and make it executable
#
# Usage
# $ dontforget let the dog back inside 10
# => I'll remind you: "let the dog back inside" in 10 minutes
#
# It can parse a little extra verbosity around the text, too
# $ dontforget to let my dog back in 10m
# => I'll remind you: "let your dog back in" in 10 minutes
#
# $ dontforget I really need to take a break in 1h
# I'll remind you: "you really need to take a break" in 60 minutes
#
# Running dontforget with no arguments will list upcoming reminders
#
# Use `dontforget cancel` or `dontforget nevermind` to cancel the last
# reminder that was created
#
# $ dontforget cancel
# Canceled "you really need to take a break"
#
# To turn on LaunchBar "large text" display
# export DF_LAUNCHBAR=true
#
# To make dontforget remain in the foreground and cancelable with ^c
# export DF_NO_BACKGROUND=true
#
# Tip:
# alias forget="dontforget cancel"
[[ -z $DF_LAUNCHBAR ]] && DF_LAUNCHBAR=false || $DF_LAUNCHBAR
[[ -z $DF_NO_BACKGROUND ]] && DF_NO_BACKGROUND=false || $DF_NO_BACKGROUND
__df()
if [[ $# == 0 ]]; then
__df_list_reminders
return
fi
if [[ $# == 1 && $1 =~ (cancel|nevermind) ]]; then
__df_cancel
return $?
fi
local instring="$*"
local timespan reminder
for arg in $@; do
if [[ $arg =~ ^[0-9]+[hms]?$ && -z $timespan ]]; then
timespan=$(echo "$arg"|sed -E 's/^([0-9]+)([HhSsMm])?$/\1 \2/')
else
reminder+=" $arg"
fi
done
length=$timespan%% *
unit=$timespan#*
if [[ $unit == "h" ]]; then
length=$(($length*60*60))
elif [[ $unit != "s" ]]; then
length=$(($length*60))
fi
reminder=$(__df_clean_reminder "$reminder")
echo "I'll remind you: \"$reminder\" in $(($length/60)) minutes"
if [[ $DF_NO_BACKGROUND == true ]]; then
sleep $length && __df_remind "$reminder"
else
sleep $length && __df_remind "$reminder" &
fi
__df_list_reminders()
IFS=$'\n'; for line in $(ps ax | grep -E "bash .*?dontforget \w+" | grep -v grep); do echo $(__df_clean_reminder $(echo "$line" | sed -E 's/.*dontforget //')); done
__df_remind()
local reminder="$*"
if [[ -n $(ps ax | grep LaunchBar.app) && $DF_LAUNCHBAR == true ]]; then
osascript -e "tell application \"LaunchBar\" to display in large type \"Time to $reminder\" with sound \"Glass\""
fi
/usr/bin/afplay /System/Library/Sounds/Glass.aiff
say "$reminder"
__df_clean_reminder()
local input="$*"
# trim whitespace
input=$(echo -e "$input" | sed -E 's/(^ *| *$)//g') | tr -s ' '
# change " I " to " you "
input=$(echo -e "$input" | sed -E 's/(^| +)[Ii]( +|$)/\1you\2/g')
# change " my " to " your "
input=$(echo -e "$input" | sed -E 's/(^| +)[Mm]y( +|$)/\1your\2/g')
# strip leading "forget" in case you alias to dont, i.e. "dont forget to..."
input=$(echo -e "$input" | sed -E 's/^ *forget//')
# strip extra words from natural language
local output=$(__df_strip_naturals "$input")
# final whitespace trim
echo -e "$output" | sed -E 's/(^ *| *$)//g' | tr -s ' '
__df_strip_naturals()
local original=$(echo "$*"|sed -E 's/^( *remind me *)//')
while [[ "$original" =~ ^[[:space:]]*(to|in|about) ]]; do
original=$(echo "$original"| sed -E 's/^ *(to|in|about) *//g')
done
if [[ "$original" =~ in[[:space:]]*$ ]]; then original=$(echo "$original"| sed -E 's/ *in *$//'); fi
echo $original | sed -E 's/(^ *| *$)//g'
__df_cancel()
local df_job=$(ps ax | grep dontforget | grep -v grep | grep -v cancel | grep -v nevermind | tail -n 1)
if [[ -z $df_job || $df_job == "" ]]; then
echo "No timer found"
return 1
else
local pid=$(echo "$df_job" | awk 'print $1')
kill $pid
local title=$(echo "$df_job" | sed -E 's/.*dontforget (.*)$/\1/')
echo "Canceled \"$(__df_clean_reminder "$title")\""
fi
__df $@
sh用于快速设置golang环境的bash脚本(代码片段)
查看详情
sh在后台运行bash脚本并退出终端(代码片段)
查看详情
sh用于快速(呃)laravel应用程序设置的bash脚本(代码片段)
查看详情
sh在bash中的任何文件集中快速查找任何文本字符串(代码片段)
查看详情
sh从bash终端删除所有heroku应用程序-无需脚本文件(代码片段)
查看详情
sh从bash终端删除所有heroku应用程序-无需脚本文件(代码片段)
查看详情
sh来自http://ss64.com/bash/ls.html(代码片段)
查看详情
终端打印(代码片段)
shebang是一个文本行,其中#!位于解释器路径之前。/bin/bash是Bash的解释器命令路径。有两种运行脚本的方式。一种是将脚本作为bash的命令行参数,另一种是授予脚本执行权限,将其变为可执行文件。将脚本作为命令行参数时... 查看详情
sh使用bash和cloudflare快速而又脏的ddns(兼容apiv4)(代码片段)
查看详情
sh暂时更改bash中的当前工作目录以运行命令-来自http://stackoverflow.com/questions/10382141/temporarily-change-(代码片段)
查看详情
sh常见的bash命令(代码片段)
查看详情
sh有用的bash命令(代码片段)
查看详情
sh简单的bash脚本(代码片段)
查看详情
sh标准的bash模板(代码片段)
查看详情
sh有趣的bash陷阱机制(代码片段)
查看详情
sh彩色的男人页#bash(代码片段)
查看详情
bash配置文件(代码片段)
...件一、shell的两种登录方式:1、交互式登录:(1)直接通过终端输入账号密码登录(2)使用“su-UserName”切换的用户执行顺序:/etc/profile-->/etc/profile.d/*.sh-->~/.bash_profile-->~/.bashrc-->/etc/bashrc2、非交互式登录:(1)suUserName(2)图形... 查看详情
sh用于执行构建的bash脚本(代码片段)
查看详情