Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # 先安装highlight, "brew install highlight"
- # Parse arguments
- usage() {
- echo "Usage: $0 [-h] [-v] [-f FILE] [-k fontsize] [-s startline] [-e endline]"
- echo " -h Help. Display this message and quit."
- echo " -v Version. Print version number and quit."
- echo " -k Specify font-size."
- echo " -f Specify file FILE."
- echo " -s Specify the line number of the file that start from ."
- echo " -e Specify the line number of the file that end to output ."
- exit
- }
- optspec="hvf:s:k:e:"
- fontsize=24
- while getopts "$optspec" optchar
- do
- case "${optchar}" in
- h) usage ;;
- v) version ;;
- f) file=${OPTARG} ;;
- k) fontsize=${OPTARG} ;;
- s) startline=${OPTARG} ;;
- e) endline=${OPTARG} ;;
- *) usage ;;
- esac
- done
- [ -z "$file" ] && usage
- # [ -n "$fontsize" ] && fontsize=$fontsize
- [ -z "$startline" ] && startline=0
- # [ -z "$endline" ] && endline=$lastline
- if [ -n "$endline" ]; then
- cat $file | head -n ${endline} | tail -n +${startline} | highlight -l -O rtf -K ${fontsize} -m ${startline} -S go - | pbcopy
- else
- cat $file | tail -n +${startline} | highlight -l -O rtf -K ${fontsize} -m ${startline} -S go - | pbcopy
- fi
Add Comment
Please, Sign In to add comment