Textmate command: Duplicate file


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  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. # do the actual duplication
  14. cp -p "$TM_FILENAME" "$new_name"
  15. # force TM to refresh project drawer and open duplicate
  16. { osascript -e 'tell application "SystemEvents" to activate' \
  17. -e 'tell application "TextMate" to activate'
  18. # open -a TextMate "$new_name";
  19. } &>/dev/null &
  20.  
  21. fi
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.