L2D Nemo/Vim/Sublime Text 3 Integration for Debian

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

L2D Nemo/Vim/Sublime Text 3 Integration for Debian

Post by Helvecta » Thu Sep 25, 2014 8:07 pm

(For Sublime Text 3 Integration, see post 3)

A year later and I'm still kickin' with Nemo. This calls for L2D integration! The script and download are posted in the next post. First, I'll show you how to integrate with Nemo, then with Vim. it's all so very simple, so let's begin!

1.) Open Nemo. (Press Win+E)
Image

2.) Navigate to ~/.local/share/nemo/scripts
Image

3.) Put the Launch In LOVE file found in the next post (remove the fake .txt extension) to this folder.
Image

4.) Press Alt+P, opening the Plugins window, then check the "Launch in Love" script on the right side of the window.
Image

5.) Open a terminal (Ctrl+Alt+T) and execute killall nemo; nemo </dev/null &>/dev/null & exit, or terminate and restart Nemo by any means at your disposal. This process refreshes the "accels" file we will edit next.

6.) Open ~/.gnome2/accels/nemo in your favourite text editor:
Image

7.) Find the line that has your script's name in it. For me, it's easy because I can search for "LOVE" (Line 26).
Image

8.) Remove the semicolon at the beginning of that line. At the end of the same line, there's also a pair of quotation marks followed by a closing parenthesis. In between the two quotation marks, enter your hotkey (pay attention to Nemo's method of binding hotkeys by looking through this file). In my example, I'll choose F7:
Image

9.) Save changes and repeat step 5.



All done! Vim integration is even easier. If you have no .vimrc file, just take the one that I've attached in the next post, remove the fake .txt extension from the file name, and move it to ~/.vimrc. Otherwise, follow these short steps:

1.) Open ~/.vimrc in your favourite text editor.
Image

2.) Copy the code in the next post, and paste it anywhere.
Image

3.) Save changes and exit.

By default, this script makes vim open love applications with the F7 key as well. Change it as desired, paying attention to Vim's method of binding hotkeys.
Last edited by Helvecta on Wed Apr 06, 2016 12:59 am, edited 19 times in total.
"Bump." -CMFIend420

User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Additional Information

Post by Helvecta » Sat Sep 27, 2014 12:21 am

Okay, I sat down today over the past year and wrote a comprehensive script to open LOVE2D projects. This is quick and dirty because no self-respecting person should learn bash, but this script is sufficient all the same. This script works on opening .love files, .zip files, directories that have "main.lua" in them and checks all parent directories and subdirectories of that directory for "main.lua". The script is as follows:

Launch In LOVE (nemo):

Code: Select all

#!/bin/bash
IFS='
'

if [ -n "$NEMO_SCRIPT_SELECTED_FILE_PATHS" ]
then
  path="$NEMO_SCRIPT_SELECTED_FILE_PATHS";
else
  path=$(echo $NEMO_SCRIPT_CURRENT_URI | sed -E 's/%20/ /g'); # "%20" to space
fi

toParse=()
toParse+=($path)

toLaunch=();
for file in "${toParse[@]}";
do
  if echo $file | grep -oe "love\|zip"
  then
    toLaunch+=("$file");
  else
    file=$(echo $file | sed -E 's/file:\/\///');
    subCount=$(echo $file | grep -o "/" | wc -l)

    for ((i=1; i<=subCount; i++)); do
      testPath=$(echo $file | grep -ow "\(/[^/]*\)\{$i\}")
      if test -e "$testPath/main.lua";
      then
        toLaunch+=($testPath)
        break;
      fi
    done
  fi
done


for file in "${toLaunch[@]}";
do
  cd $file
  love $file &
done
.vimrc:

Code: Select all

map <F7> :! path='%:p'; subCount=$(echo "$path" <BAR> grep -o "/" <BAR> wc -l); for ((i=subCount-1; i>=1; i--)); do testPath=$(echo "$path" <BAR> grep -ow "\(/[^/]*\)\{$i\}"); if [ -f "${testPath}/main.lua" ]; then cd "$testPath"; nohup love "$testPath" >/dev/null 2>&1 & break; fi; done;<CR><CR>
imap <F7> <ESC>:! path='%:p'; subCount=$(echo "$path" <BAR> grep -o "/" <BAR> wc -l); for ((i=subCount-1; i>=1; i--)); do testPath=$(echo "$path" <BAR> grep -ow "\(/[^/]*\)\{$i\}"); if [ -f "${testPath}/main.lua" ]; then cd "$testPath"; nohup love "$testPath" >/dev/null 2>&1 & break; fi; done;<CR><CR>

UPDATE: Added support for multiple files at once! (select multiple folders, hit hotkey)

UPDATE 2: Fixed script not working with folders containing spaces.

UPDATE 3: Vim L2D launch script added.

UPDATE 4: Fixed not opening correctly due to folder/file permissions and problems launching from directories that have spaces in them.

UPDATE 5: "love "$testPath";" to "love "$testPath" &" -- the latter stops reviewing the compiled game from interrupting vim. Changed the way the script functions to not interfere with undo tree and to not return anything.

UPDATE 6: Moved subCount variable definition location for performance purposes, added "cd $file" before love executes to have the correct path when launching. In my case, it stops errors involving the require() function when the definition of package.path is altered.

UPDATE 7: Added nohup... no more output being written to Vim!

UPDATE 8: Edited vim script to remove pesky nohup.out file. Major edit to Nemo script; Mint loves reinventing the wheel because they hate me. Updated OP to reflect these changes.
Attachments
Launch In LOVE.txt
(remove .txt from the filename, I blame the forums)
Add to ~/.local/share/nemo/scripts
(739 Bytes) Downloaded 70 times
.vimrc.txt
(remove .txt from the filename, I blame the forums)
Add to ~/
(600 Bytes) Downloaded 70 times
"Bump." -CMFIend420

User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: L2D Nemo/Vim/Sublime Text 3 Integration for Debian

Post by Helvecta » Wed Apr 06, 2016 1:04 am

For Sublime Text Integration, follow these instructions:

1.) take the below code and save it as "build.sh" wherever you like:

Code: Select all

#!/bin/bash
path="$1";
subCount=$(echo "$path" | grep -o "/" | wc -l);
for ((i=$subCount-1; i>=1; i--)); do 
    testPath=$(echo "$path" | grep -ow "\(/[^/]*\)\{$i\}");
    if [ -f "${testPath}/main.lua" ]; then 
        cd "$testPath";
        nohup love "$testPath" >/dev/null 2>&1 & break;
    fi;
done;
(you may need to execute "chmod +x BUILDPATH" in terminal for execution permission)

2.) Open Sublime Text 3, then go to Tools > Build System > New Build System...
3.) in the window that opens up, paste this code (make sure to change [PATHTOBUILD.SH] to the path of the file from step 1):

Code: Select all

{ "cmd": ["PATHTOBUILD.SH", "$file"], }
4.) Save the file, preferably as l2d, love2d, or something similar.
5.) Done! You can execute this by pressing ctrl+b, or by pressing F7.
"Bump." -CMFIend420

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests