SHARE
TWEET

Untitled

a guest Jan 20th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # 先安装highlight, "brew install highlight"
  3. # Parse arguments
  4. usage() {
  5.     echo "Usage: $0 [-h] [-v] [-f FILE] [-k fontsize] [-s startline] [-e endline]"
  6.     echo "  -h  Help. Display this message and quit."
  7.     echo "  -v  Version. Print version number and quit."
  8.     echo "  -k  Specify font-size."
  9.     echo "  -f  Specify file FILE."
  10.     echo "  -s  Specify the line number of the file that start from ."
  11.     echo "  -e  Specify the line number of the file that end to output ."
  12.     exit
  13. }
  14.  
  15. optspec="hvf:s:k:e:"
  16. fontsize=24
  17.  
  18. while getopts "$optspec" optchar
  19. do
  20.   case "${optchar}" in
  21.     h) usage ;;
  22.     v) version ;;
  23.     f) file=${OPTARG} ;;
  24.     k) fontsize=${OPTARG} ;;
  25.     s) startline=${OPTARG} ;;
  26.     e) endline=${OPTARG} ;;
  27.     *) usage ;;
  28.   esac
  29. done
  30.  
  31. [ -z "$file" ] && usage
  32.  
  33. # [ -n "$fontsize" ] && fontsize=$fontsize
  34. [ -z "$startline" ] && startline=0
  35. # [ -z "$endline" ] && endline=$lastline
  36. if [ -n "$endline" ]; then
  37.   cat $file | head -n ${endline} | tail -n +${startline} |  highlight -l -O rtf -K ${fontsize} -m ${startline} -S go -  | pbcopy
  38. else
  39.   cat $file | tail -n +${startline} |  highlight -l -O rtf -K ${fontsize} -m ${startline} -S go -  | pbcopy
  40. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top