Sublime Forum

[Solved] How to use linux paths on windows for build variables as $packages

#1

This is may build. After run it I get:

sh: D:UserDropboxApplicationsSoftwareVersioningSublimeTextDataPackages/SublimeBuildSystem/Uncrustify.sh: No such file or directory

So, we may see, the inverted slashes \ are being interpreted as escape characters. It is needed double \\ or / as used on the ending path.

{
    "working_dir": "$file_path",
    // "selector": "source.AmxxPawn, source.AMXX",
    
    "shell": true,
    "cmd": ["bash", "--login", "-i", "-c", "sh $packages/SublimeBuildSystem/Uncrustify.sh", "$file"],
    
    "target": "ansi_color_build",
    "syntax": "Packages/ANSIescape/ANSI.tmLanguage"
}
0 Likes

#2

Use the shell script to do the conversion with sed:

{
    "working_dir": "$file_path",
    // "selector": "source.AmxxPawn, source.AMXX",
    
    "shell": true,
    "cmd": ["sh", "$packages/SublimeBuildSystem/Uncrustify.sh", "$file"],
    
    "target": "ansi_color_build",
    "syntax": "Packages/ANSIescape/ANSI.tmLanguage"
}

Where Uncrustify.sh is:

# Convert the windows path to linux path
FILE_TO_APPLY=$(echo $1 | sed -e 's@\\@\/@g')

# Declare an array variable. You can access them using echo "${arr[0]}", "${arr[1]}"
declare -a terminal_list=( "uncrustify" "uncrustify.exe" )

# Now loop through the above array
for current_terminal in "${terminal_list[@]}"
do
    if command -v $current_terminal >/dev/null 2>&1;
    then
        $current_terminal -c $UNCRUSTIFY_SETTINGS_FILE --no-backup $FILE_TO_APPLY
    fi
done
0 Likes