Posted By

tictoc on 01/22/07


Tagged

command textmate copy duplicate


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

koncept
jannisg
quickredfox
curiousstranger


Textmate command: Duplicate file


 / Published in: Other
 

  1. # so we can work with relative paths
  2. cd "$TM_DIRECTORY"
  3.  
  4. # construct a default name for the duplicate
  5. def_name=`perl -pe <<<"$TM_FILENAME" 's/^(.*?)(\.[^.]*)?$/$1 copy$2/'`
  6.  
  7. # prompt user for a name
  8. CocoaDialog inputbox --text "$def_name" --button1 "Duplicate" --button2 "Cancel"|{
  9.  
  10. # if user selected 'Duplicate' and file doesn't exist
  11. read res; read new_name;
  12. if [[ "$res" == "1" && ! -e "$new_name" ]]; then
  13.  
  14. # do the actual duplication
  15. cp -p "$TM_FILENAME" "$new_name"
  16.  
  17. # force TM to refresh project drawer and open duplicate
  18. { osascript -e 'tell application "SystemEvents" to activate' \
  19. -e 'tell application "TextMate" to activate'
  20.  
  21. # open -a TextMate "$new_name";
  22. } &>/dev/null &
  23.  
  24. fi
  25. }

Report this snippet  

You need to login to post a comment.