[TxMt] Duplicate current file (was: TextMate Feature Request)

Allan Odgaard allan at macromates.com
Wed Sep 7 12:23:31 UTC 2005

On 06/09/2005, at 19.29, Jeff Powell wrote:

[ I've cc'ed the ML, since this is a popular request, yet you're the  
first to suggest solving the problem with a command :) ]

> It's pretty basic really --- I've got a project setup in TM and  
> quite frequently, I will need to make a copy of a file inside of  
> the project [...] Can I make a command that might do the duplication?

Yes, make a command that saves current file (since it duplicates  
what's on disk). The actual command should be:


# so we can work with relative paths

# construct a default name for the duplicate
def_name=`perl -pe <<<"$TM_FILENAME" 's/^(.*?)(\.[^.]*)?$/$1 copy$2/'`

# prompt user for a name
CocoaDialog inputbox --text "$def_name" --button1 "Duplicate" -- 
button2 "Cancel"|{

    # if user selected 'Duplicate' and file doesn't exist
    read res; read new_name;
    if [[ "$res" == "1" && ! -e "$new_name" ]]; then

       # do the actual duplication
       cp -p "$TM_FILENAME" "$new_name"

       # force TM to refresh project drawer and open duplicate
       { osascript -e 'tell application "SystemEvents" to activate' \
                   -e 'tell application "TextMate" to activate'
         open -a TextMate "$new_name"; } &>/dev/null &


More information about the textmate mailing list