ããã¹ãã§ãªããã¡ã¤ã«ã®diffï¼å·®åï¼ãã¨ãæ¹æ³
AppleScriptã¯ã¹ã¯ãªããè¨èªãªãã ãã©ããã¡ã¤ã«ã«ä¿åããã¨ãã¯AppleScriptå½¢å¼ã«ã³ã³ãã¤ã«ï¼å¤æï¼ãããããã®çµæãAppleScriptã¨ãã£ã¿ã§ã¯äººéãç解ã§ããã³ã¼ãã«è¦ããã®ã«ãæ®éã®ããã¹ãã¨ãã£ã¿ã§éãã¨ãããªç¶æ ã
ãã®å®æ ã¯ãAppleScriptç¬èªã®ãã¤ããªãã¡ã¤ã«ãªã®ã ããã¤ããªãã¡ã¤ã«ã®çãã¨ããã¯ãdiffãå®è¡ãã¦ããã®ã¾ã¾ã§ã¯å·®åãã¨ããªããã¨ãã©ããã¦ãå·®åãã¨ãããã¨æãã®ãªãããã£ããAppleScriptãã¡ã¤ã«ãéãã¦ãããã¹ããã¡ã¤ã«ã¨ãã¦ä¿åãããã¡ã¤ã«ã«å¯¾ãã¦diffãå®è¡ãããããªãã
ããããããã§ã¯æéããããããããæ軽ã«diffã§ããªãã¨ãããã使ããªããªãããããªè¨³ã§ãAppleScriptã¯ãã¤ããªãã¡ã¤ã«ãªã®ã ããããããããªããã¨ä»¥åãã諦ãã¦ããã¨ããããã£ããï¼Gitã®ãã®ç´ æ´ãããä»çµã¿ãç¥ãã¾ã§ã¯ï¼ã¨ããããGitã«ã¯ãã¡ã¤ã«ã¢ããªãã¥ã¼ãã¨ããã¹ãã³ã³ãã¼ãã¨ããè¨å®ãããã
# .gitattirbutesãããã¯.git/info/attributesã®è¨å®
*.scpt diff=applescript
# git configã®è¨å®
$ git config diff.applescript.textconv osadecompile
ãã®ããã«è¨å®ãã¦ããã¨ã.scptå½¢å¼ã®AppleScriptãã¡ã¤ã«ã«å¯¾ãã¦diffãå®è¡ããã¨ãã«ãäºåã«osadecompileãå®è¡ããçµæã«å¯¾ãã¦diffãã¦ãããã®ã ãosadecompileã¯.scptå½¢å¼ã®AppleScriptãã¡ã¤ã«ãããã¹ãã«å¤æãã¦ãããOSXç¬èªã®ã³ãã³ããã¤ã¾ããããã¹ãã«å¤æãããAppleScriptã®å·®åãã¨ããã®ã ï¼ãã£ã¦ãããã¨ã¯ãæä½æ¥ã§ããã¹ãã«å¤æãã¦diffãå®è¡ãã¦ããã®ã¨åããã¨ãªãã ãã©ãä¸åº¦è¨å®ãã¦ãã¾ãã°ããã®ãªãã¸ããªã§ã¯æ®éã«diffãå®è¡ããã ãã§ãå½ç¶ã®ããã«AppleScriptã®å·®åãã¨ãã¦ãã¾ãã¨ãããç´ æ´ãããã
ãã®ãããªæåçã«ç´ æ´ãããæ å ±ãæ¸ç±ãå ¥éGitãã«ã¯ ããã ã¨æ¸ãã¦ããããã¾ãã«ã ããã ã¨æ¸ãã¦ããã®ã§ããªããªãæ°ä»ããªãã£ã...ãå®ã¯ãä½åº¦ãèªã¿ç´ãã¦ããä¸ã§ããããæ°ä»ããã®ã ããã®è¾ºãã®è©±é¡ã¯14ç« ãã¡ã¤ã«ã¢ããªãã¥ã¼ãã®ä¸ã§ãæ°ãã便å©ãªä¸ã¤ã®æ©è½ï¼P248ãã¤ããªãã¡ã¤ã«ã®æ¯è¼ï¼ã¨ãã¦ç´¹ä»ããã¦ããããã®ä»ã«ããã¡ã¤ã«ã¢ããªãã¥ã¼ãï¼ä½ããã®è¨å®ã«ãããç´ æ´ããã便å©ãªæ©è½ãæã«å ¥ãããã¨ãã§ããã®ã ã*1
ä¸æ¦diffã®æ©æµãçµé¨ããã¨ãå·®åãã¨ããªãç°å¢ã¨ããã®ãã¨ã¦ãä¸å®ã«æãã¦ããããã®ãMacBook Proã®Retinaã¢ãã«ã®ãã¹ã¯ããããã¯ãã£ã«æ¡ç¨ãããåç家ã®Kent Shiraishiæ°ãã常æã¢ãã¿ãï¼å°ä¸¦ã¹ã¦åçã®è²åãã®ãã§ãã¯ããã¦ããããã§ãããæ°ããèªåã®æè¦ãªãã¦å½ã¦ã«ãªããªããæ£ç¢ºãªè²ãåç¾ããããã«ã¯å®ç§ã«ãã¸ã¿ã«èª¿æ´ãããã¢ãã¿ã並ã¹ã¦ããã®éããæãã¦ç¾åããããã§ãããã¤ã¾ããè²ã®å·®åãè¦ã¦ããã®ã ï¼å·®åãç¥ããã¨ã¯ã¨ã¦ã大åãåçã§ããããã¹ãã§ãã
ã¨ãã訳ã§ããããããã®ãå¯è½ãªéãæ軽ã«diffã§ããç°å¢ãä½ã£ã¦ãããããã¨å¸¸ã«æã£ã¦ãããã ããããã¡ãã前回ä½ãå§ããdropbox_diff.shã§ããAppleScriptã®å·®åãã¨ããããã«ãã¦ã¿ããããã«ãããã¹ãã«å¤æããã³ãã³ãããããã°ããããããã®ã®å·®åãã¨ããããã«ãªããï¼ãªããããã¹ããJPEG(exifã ã)ã®å·®åã ã£ã¦ã¨ãããPDFã表è¨ç®ã½ããã®ãã¡ã¤ã«ã ã£ã¦ã工夫ããã°ã©ãã«ããªããããããªããï¼
convert_diffããã¸ã§ã¯ãã®éå§
DropboxãGitãªãã¸ããªã®ä¸ã§ã¯AppleScriptã®å·®åãè¦ãããããã«ãªã£ãããããªãã¨ããã以å¤ã®ç°å¢ã§ãæ軽ã«diffããããªãã®ã人æ ããªãã°ãdropbox_diff.shã«çµã¿è¾¼ãã ããã¹ãå¤ææ©è½ã®é¨åã ããåãåºãã¦ãdiffã³ãã³ãã®ã©ããã¼ãä½ã£ã¦ãã¾ãã°ããã®ã ã.scptãªã©ã®ç¹å®ã®æ¡å¼µåã®ãã¡ã¤ã«ã ã£ãããããã¹ãã³ã³ãã¼ããã¦diffããããã以å¤ã¯ãã®ã¾ã¾diffããããããªåä½ãããconvert_diff.shãä½ã£ã¦ã¿ãã
- ã¨ããããã.scptã.rtfã.jpgã®æ¡å¼µåã«å¯¾ãã¦ãããã¹ãå¤æããããã«ãã¦ã¿ãã
#!/bin/bash convert() { if [ "${PATH1##*.}" = "scpt" ] && [ "${PATH2##*.}" = "scpt" ]; then echo -n 'osadecompile' elif [ "${PATH1##*.}" = "rtf" ] && [ "${PATH2##*.}" = "rtf" ]; then echo -n 'textutil -convert txt -stdout' elif [ "${PATH1##*.}" = "jpg" ] && [ "${PATH2##*.}" = "jpg" ]; then echo -n 'exiftool' else echo -n 'cat' fi } OPTION=("$@") PATH1=${OPTION[$(($# - 2))]} PATH2=${OPTION[$(($# - 1))]} unset OPTION[$(($# - 1))] unset OPTION[$(($# - 2))] if [ -f "$PATH1" ] && [ -f "$PATH2" ] && [ "`convert`" != 'cat' ]; then diff "${OPTION[@]}" <(`convert` "$PATH1") <(`convert` "$PATH2") echo -e "\n\`diff ${OPTION[@]} <(`convert` \"$PATH1\") <(`convert` \"$PATH2\")\`\n" else diff "$@" fi
- ããã»ã¹ç½®ãæãæ©è½ãå©ç¨ããã¨ãä¸æãã¡ã¤ã«ãä½ããã«å
ãã¡ã¤ã«ãå¤æã§ããã®ã§ä¾¿å©ï¼
- ã³ãã³ã Tips - UNIX & Linux ã³ãã³ãã»ã·ã§ã«ã¹ã¯ãªãã ãªãã¡ã¬ã³ã¹ï¼ç´ æ´ãããæ å ±ã«æè¬ã§ãï¼ï¼
- -<(ã³ãã³ã) ï¼ <( )å ã®ã³ãã³ãã®å®è¡çµæããã¡ã¤ã«ã¨ãã¦æ±ã£ã¦ãããã
$ diff -u file1.scpt file2.scpt
- ããã¹ãã«å¤æãã¦ããdiffããã«ã¯ã以ä¸ã®ããã«ä¿®æ£ããã°ããã®ã ã
$ diff -u <(osadecompile file1.scpt) <(osadecompile file2.scpt)
ã«ã©ã¼è¡¨ç¤º
- ããããã°ãGitã®diffã§ã¯ã«ã©ã¼è¡¨ç¤ºãè¦ãããã£ãã
- å¤æ´ç®æãç®ç«ã£ã¦ããã¨ãæè¦çã«æ¼ããªããã§ãã¯ã§ããã
ããã ãè²ãä»ãããï¼
- 調ã¹ã¦ã¿ãã¨ããã®åã®ã¨ããã®colordiffã³ãã³ããè¦ã¤ãã£ãã
- diffãã«ã©ã¼ã§è¡¨ç¤ºãã - A Way of Codeï¼ç´ æ´ãããæ å ±ã«æè¬ã§ãï¼ï¼
- ãã£ããã¤ã³ã¹ãã¼ã«ãã¦ã¿ãã
$ brew install colordiff
- 使ãæ¹ã¯diffã®ä»£ããã«colordiffãå®è¡ãããã
$ colordiff file1 file2
- diffã®åºåã¨ãã¤ãã§æ¥ç¶ãã¦ãè²ä»ãããã
$ diff -u file1 file2|colordiff
- æ¢åã®diffã®æ©è½ããã¹ã¦ä½¿ãããã®ã§ãå¾è ã®ãã¤ãã§æ¥ç¶ãã¦ã¿ãã
- colordiffã¯ããã¤ãã§æ¥ç¶ããã¨ãã®åä½ããµãã¼ããã¦ããªãããã ã
$ echo 'hello'|diff -u - ~/Desktop/hello.txt ...ä¸ç¥... -hello +hello world!!
$ echo 'hello'|colordiff -u - ~/Desktop/hello.txt ...ä¸ç¥... +hello world!!
- ãããããã¤ããå©ç¨ããã¨ã巨大ãªãã¡ã¤ã«ã®diffã§åé¡ãçãããããããªãã
- èªåã®ç°å¢ã§ã¯ãç´26ä¸åã®æåæ°å¶éãããã®ã ã
$ sysctl -A kern.argmax
kern.argmax: 262144
- èªåã®ä½¿ãæ¹ã§ã¯ä»ã®ã¨ãããããã»ã©å·¨å¤§ãªãã¡ã¤ã«ãdiffããéè¦ã¯ãªãã®ã§ã
- ç´26ä¸æåã®å¶éããããã¨ã念é ã«ç½®ããªããããã¤ãã§æ¥ç¶ãã¦ã¿ãã
#!/bin/bash convert() { if [ "${PATH1##*.}" = "scpt" ] && [ "${PATH2##*.}" = "scpt" ]; then echo -n 'osadecompile' elif [ "${PATH1##*.}" = "rtf" ] && [ "${PATH2##*.}" = "rtf" ]; then echo -n 'textutil -convert txt -stdout' elif [ "${PATH1##*.}" = "jpg" ] && [ "${PATH2##*.}" = "jpg" ]; then echo -n 'exiftool' else echo -n 'cat' fi } OPTION=("$@") PATH1=${OPTION[$(($# - 2))]} PATH2=${OPTION[$(($# - 1))]} unset OPTION[$(($# - 1))] unset OPTION[$(($# - 2))] if [ -f "$PATH1" ] && [ -f "$PATH2" ] && [ "`convert`" != 'cat' ]; then diff "${OPTION[@]}" <(`convert` "$PATH1") <(`convert` "$PATH2")|colordiff echo -e "\n\`diff ${OPTION[@]} <(`convert` \"$PATH1\") <(`convert` \"$PATH2\")\`\n" else diff "$@"|colordiff fi
- å·®å
$ dropbox_diff.sh convert_diff.sh @@ -21,10 +21,10 @@ if [ -f "$PATH1" ] && [ -f "$PATH2" ] && [ "`convert`" != 'cat' ]; then unset OPTION[$( ($# - 1) )] unset OPTION[$( ($# - 2) )] - diff "${OPTION[@]}" <(`convert` "$PATH1") <(`convert` "$PATH2") + diff "${OPTION[@]}" <(`convert` "$PATH1") <(`convert` "$PATH2")|colordiff echo -e "\n\`diff ${OPTION[@]} <(`convert` \"$PATH1\") <(`convert` \"$PATH2\")\`\n" else - diff "$@" + diff "$@"|colordiff fi
ããã§AppleScriptãªã©ãæ軽ã«diffã§ããããã«ãªã£ãï¼å¿«é©ãå¿«é©ã
æ¹è¯ãã¼ã¸ã§ã³
- convert_diff.shã¯ã次に日記ã§ããæ±ç¨çã«ä½¿ããããã«ã以ä¸ã®ããã«ä¿®æ£ãããã
#!/bin/bash convert() { case $1 in *.scpt ) echo -n "osadecompile" ;; *.rtf ) echo -n "textutil -convert txt -stdout" ;; *.jpg ) echo -n "exiftool" ;; * ) echo -n "cat";; esac } OPTION=("$@") PATH1=${OPTION[$(($# - 2))]} PATH2=${OPTION[$(($# - 1))]} unset OPTION[$(($# - 1))] unset OPTION[$(($# - 2))] # ä¸æ¹ããã£ã¬ã¯ããªã ã£ãããä»æ¹ã®ãã¡ã¤ã«åãè£ã if [ -d "$PATH1" ] && [ -f "$PATH2" ]; then PATH1="$PATH1/`basename "$PATH2"`" elif [ -f "$PATH1" ] && [ -d "$PATH2" ]; then PATH2="$PATH2/`basename "$PATH1"`" fi # 両æ¹ã¨ããã£ã¬ã¯ããªã ã£ãããå¤æããã«diffãå®è¡ãã if [ -d "$PATH1" ] && [ -d "$PATH2" ]; then echo "\`diff" "$@""|colordiff'" diff "$@"|(`which colordiff`||`which cat`) else echo "\`diff ${OPTION[@]} <(`convert "$PATH1"` \"$PATH1\") <(`convert "$PATH2"` \"$PATH2\")|colordiff'" diff "${OPTION[@]}" <(`convert "$PATH1"` "$PATH1") <(`convert "$PATH2"` "$PATH2")|(`which colordiff`||`which cat`) fi
colordiff 追å æ å ±
- è¨å®ãã¡ã¤ã«ï¼èªå好ã¿ã®è²ãªã©ãè¨å®ã§ããï¼
- /etc/colordiffrcï¼èªåã§makeããå ´åï¼
- /usr/local/etc/colordiffrcï¼Homebrewã§ã¤ã³ã¹ãã¼ã«ããå ´åï¼
# Example colordiffrc file for dark backgrounds # # Set banner=no to suppress authorship info at top of # colordiff output banner=no # By default, when colordiff output is being redirected # to a file, it detects this and does not colour-highlight # To make the patch file *include* colours, change the option # below to 'yes' color_patches=no # # available colours are: white, yellow, green, blue, # cyan, red, magenta, black, # darkwhite, darkyellow, darkgreen, # darkblue, darkcyan, darkred, # darkmagenta, darkblack # # Can also specify 'none', 'normal' or 'off' which are all # aliases for the same thing, namely "don't colour highlight # this, use the default output colour" # plain=off newtext=blue oldtext=red diffstuff=magenta cvsstuff=green
- ä¸è¨ãªãªã¸ãã«ã®è¨å®ãã¡ã¤ã«ããã¼ã ãã©ã«ãã«ã³ãã¼ãã¦ãèªå好ã¿ã«ä¿®æ£ããã®ã ã
$ cp /usr/local/etc/colordiffrc ~/.colordiffrc
- èªåã®ç°å¢ã§Gitããã©ã«ã風ã«è¦ããè¨å®
banner=no color_patches=no #diff_cmd=diff #ã³ã¡ã³ãã¢ã¦ãããªãã¨ã¨ã©ã¼ã«ãªã£ã¦ãã¾ã£ã plain=off newtext=darkgreen oldtext=darkred diffstuff=cyan cvsstuff=red
*1:å ¥éGitã¯ãèªã¿ç´ã度ã«æ°ããªçºè¦ãããããã¶ãããã¹ã¦ã®æ©è½ã®è§£èª¬ãå¹³çã«ç¶²ç¾ ããã¦ããã®ã ã¨æãããã®ãããGitãããç¨åº¦ç¥ããªãã¨èªã¿ã«ããã®ã ããGitãããã«ä¾¿å©ã«ä½¿ãããã¨æã£ãã¨ãã«ã¯ãããã«ã¯åé¡è§£æ±ºã®ãã³ããããããããã®ã ãã¿ã¤ãã«ãå ¥éã¨ãªã£ã¦ããããããã¯Gitã®åå ¸ãªã®ã§ããã