3 Replies Latest reply: May 10, 2010 4:55 PM by Samuel Smith2
Samuel Smith2 Level 1 Level 1 (5 points)
When using nano text editor in terminal to edit a shell file, it reformats text that I paste in from the clipboard. I can't find any way to disable this. There is nothing in the nanorc docs that at all seems to apply. This is on a default configuration for nano on OS X Snow leopard.

Here is an example:

If I cut the following text from text edit or bbedit:

#!/bin/bash --
/usr/local/bin/fixsyncpermissions.sh
Eden Nelson - 4/14/08
Sam Smith 4/15/08
755 = rwxrwxr-x
#set -vx

SHAREPOINTPATH="/Volumes/SBData/ServerSync"
CHMODMODE="775"
CHMODUSER="admin"
CHMODGROUP="admin"

echo "Start Permissions Fix on $SHAREPOINTPATH"

chown -R "$CHMODUSER":"$CHMODGROUP" "$SHAREPOINTPATH"
chmod -R "$CHMODMODE" "$SHAREPOINTPATH"

echo "Completed Permissions Fix on Volumes/Aux/ServerSync"

exit
Then paste it into nano
$ sudo nano fixsyncpermissions.sh

and then command v to paste

It shows up like this in Nano

#!/bin/bash --
/usr/local/bin/fixsyncpermissions.sh Eden Nelson - 4/14/08 Sam Smith 4/15/08 755 = rwxrwxr-x set -vx
SHAREPOINTPATH="/Volumes/SBData/ServerSync" CHMODMODE="775" CHMODUSER="admin" CHMODGROUP="admin" echo "Start Permissions Fix on $SHAREPOINTPATH" chown -R
"$CHMODUSER":"$CHMODGROUP" "$SHAREPOINTPATH" chmod -R "$CHMODMODE" "$SHAREPOINTPATH" echo "Completed Permissions Fix on Volumes/Aux/ServerSync" exit
Notice that is stripped the comment symbols '#' from the comment lines and concatenated them
then it stripped the carriage returns from the other lines and concatenated them.

Anybody have a clue as to what is causing this?

1.8 Dual G5
  • Mark Jalbert Level 5 Level 5 (4,585 points)
    Hi Sam,

    It 's all about [newline|http://en.wikipedia.org/wiki/Newline] . Either configure your gui text editors to save files with " " (unix line endings) or convert them before you copy and paste them into nano.

    #!/bin/bash -- # loose the -- after bash
    #comment each line or it may be read
    #/usr/local/bin/fixsyncpermissions.sh
    #Eden Nelson - 4/14/08
    #Sam Smith 4/15/08
    #755 = rwxrwxr-x
    #set -vx
  • Samuel Smith2 Level 1 Level 1 (5 points)
    Yes I already double checked that bbedit is set to newline mode and that the particular
    file is using newlines. I doubled checked by making a copy of the file in mac return line mode and then using $ more to display both. The newline version displays correctly. The carriage return version has lots of ^M in more.

    But it is not the line mode in a gui text editor.

    The same thing happens when I copy and paste from terminal.

    For example if I put the information in file.txt with newlines.
    Then do in terminal

    $ cat file.txt
    mouse select catted text in terminal
    cmd-c
    $ nano newfile.sh
    cmd-v

    The problem happens.

    Its something happening with nano and the clipboard that is not just newline. Like some kind of
    filter.

    Please note that if it were just a newline problem it would not be deleting the # symbols.
  • Samuel Smith2 Level 1 Level 1 (5 points)
    I found the problem. It is a configuration issue with apple terminal.
    If the counter intuitively labeled option"

    "Paste newlines as carriage returns" is ENABLED
    then the problem occurs.
    If the option is DISABLED then the problem goes away.

    So I am speculating that nano expects the mac clipboard to always be carriage returns and
    when it isn't it messes up. Or else the terminal UI is messed up and the option is mislabeled.