- Home /
open C# scripts on Linux in native monodevelop
Linux? Did I read it right?
Hell yeah! I have been using Unity on arch linux for some time and there's a great script available that automates the installation and handles workarounds for errors.
But, I couldn't get C# autocompletion in any text editor the way I was used to in monodevelop so I wrote the script below that formats parameters (*-csharp.sln, filename.cs, fileline) in a way monodevelop can handle.
Test and let me know how it goes, good luck!
~Radivarig
It is an important code snippet that answers a question of how to, therefore it is an answer and belongs here.
Answer by Radivarig · Feb 09, 2015 at 04:23 AM
Once you install your Unity on Linux:
save this script as unity3d_native_monodevelop.sh
this is a bash script, give it execution permission with
chmod +x unity3d_native_monodevelop.sh
open Unity and go to
Edit>Preferences>ExternalEditor
and select this scriptput
"$(File)" $(Line)
as parameters
That's it!
#!/bin/bash
if [ -z "$1" ]; then exit 1; fi
if [ "$1" == "--nologo" ]
then
WIN_FILE_PATH="${3%;*}"
FILE_LINE="${3##*;}"
else
WIN_FILE_PATH="$1"
FILE_LINE="$2"
fi
if [ "$FILE_LINE" == "-1" ]; then FILE_LINE="0"; fi
FILE_PATH=$(winepath -u "$WIN_FILE_PATH")
if [[ "$WIN_FILE_PATH" == *.sln ]]; then FILE_PATH=$(dirname "$FILE_PATH"); fi
SLN_DIR="${FILE_PATH%%/Assets/*}"
SLN_PATH=$(find "$SLN_DIR" -maxdepth 1 -name "*-csharp.sln")
SLN_NAME="${SLN_PATH#${SLN_DIR}/}"
SLN_NAME="${SLN_NAME#$?}"
LOCAL_FILE_PATH="${FILE_PATH#$SLN_DIR}"
LOCAL_FILE_DIR=$(dirname "$LOCAL_FILE_PATH")
FILE_NAME="${LOCAL_FILE_PATH#${LOCAL_FILE_DIR}/}"
export WINEPREFIX="${SLN_DIR%%/dosdevices/z*}/"
if [[ $FILE_PATH == *".js" ]]
then
SLN_NAME="${SLN_NAME/-csharp/}"
PREV_SLN_NAME=$(head -n 1 "${SLN_DIR}/sln_name_of_last_monodevelop_call_js")
WIN_SLN_DIR="$(winepath -w "$SLN_DIR")"
MD_PATH="${WINEPREFIX}drive_c/Program Files/Unity/MonoDevelop/bin/MonoDevelop.exe"
if [ "$(pidof MonoDevelop.exe)" ] && [ $PREV_SLN_NAME == $SLN_NAME ]
then wine "$MD_PATH" "$WIN_FILE_PATH;$FILE_LINE"
else wine "$MD_PATH" "${WIN_SLN_DIR}\\$SLN_NAME $WIN_FILE_PATH;$FILE_LINE"
fi
echo "$SLN_NAME" > "${SLN_DIR}/sln_name_of_last_monodevelop_call_js"
exit 0
fi
COUNT="${LOCAL_FILE_PATH//[^\/]}"
COUNT="${#COUNT}"
COUNT="$((COUNT - 2))"
BACKWARD_SLN_DIR=""
for i in $(seq 0 $COUNT); do BACKWARD_SLN_DIR="${BACKWARD_SLN_DIR}../"; done
ln -s "/" "${SLN_DIR}/Z:"
ln -s "${WINEPREFIX}dosdevices/c:" "${SLN_DIR}/C:"
cd "${SLN_DIR}$LOCAL_FILE_DIR"
PREV_SLN_NAME=$(head -n 1 "${SLN_DIR}/sln_name_of_last_monodevelop_call")
echo "$SLN_NAME" > "${SLN_DIR}/sln_name_of_last_monodevelop_call"
MD_PATH="$(which monodevelop)"
if [[ "$WIN_FILE_PATH" == *".sln" ]]
then
if [ -z "$(pidof monodevelop)" ]
then "$MD_PATH" "$SLN_NAME"
fi
else
if [ "$(pidof monodevelop)" ] && [ $PREV_SLN_NAME == $SLN_NAME ]
then "$MD_PATH" "$FILE_NAME;$FILE_LINE"
else "$MD_PATH" "${BACKWARD_SLN_DIR}$SLN_NAME $FILE_NAME;$FILE_LINE"
fi
fi
exit 0
~Radivarig
That's interesting because unity's first arg for me is --nologo (which then breaks your script at line 4 for me as winepath returns nothing). In fact the args I'm seeing are --nologo sln_path file_path;line_number. Also my version of this keeps opening new monodevelop windows - sigh.
I've got another report that Unity doesn't send specified arguments so I made a fix for that above. Thanks for testing!
Just for the record.. underlying problem here is due to the difference between ArchLinux and Ubuntu and its derivatives. Ubuntu uses dash for /bin/sh and has monodevelop in /usr/bin/monodevelop. So change the first line to /bin/bash and replace /bin/monodevelop with /usr/bin/monodevelop on ubuntu.
I think installing monodevelop can help too ;) sudo apt-get install monodevelop -y
. Won't run unity's built in monodevelop, but at least it worked for me on ubuntu. Thanks for sharing this script.
Your answer
Follow this Question
Related Questions
Remove automatic space before () in MonoDevelop autocomplete 1 Answer
When i open C#-Scripts with MonoDevelop, MonoDevelop shows starting screen. 2 Answers
Autocomplete not working for inherted methods 1 Answer
I use Ubuntu, but Monodevelop Autocomplete is not working. is there some additional Add in ? 1 Answer
New Scripts have no autocomplete.. 1 Answer