Skip to content

Commit

Permalink
scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Nov 14, 2020
1 parent a7e7df5 commit 78cfc2d
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,35 @@ TermPlug is a native app that runs on top (in front of) the terminal and can pre

## Installation

TODO
### TermPlug.app

Open the `macos` folder in Terminal and run `./build-dist` to build the app and `./install` to copy it to `/Applications`

### Bash

Copy `bash/termplug` to `~/.local/bin/termplug`.

```
mkdir -p ~/.local/bin
cp bash/termplug ~/.local/bin/termplug
```

If `~/.local/bin` is not in your path add

```
export PATH=$PATH:~/.local/bin
```

to your `~/.bashrc`.

### Ranger

Copy the `ranger/commands.py` and the `ranger/plugins/` directory to `~/.config/ranger`.

If you already have a `~/.config/ranger/commands.py` file you can add the imports and the two functions to it.

In `~/.config/ranger/rc.conf` map a key (like `\`) to toggle termplug:

```
map \ toggle_termplug
```
7 changes: 7 additions & 0 deletions bash/termplug
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if [[ $1 == --exit ]]; then
killall TermPlug
else
open -g -a /Applications/TermPlug.app "$1"
fi
4 changes: 4 additions & 0 deletions macos/build-dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

rm -rf build
xcodebuild build
3 changes: 3 additions & 0 deletions macos/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

rsync -rltp -vh --delete build/Release/TermPlug.app/ /Applications/TermPlug.app
39 changes: 39 additions & 0 deletions ranger/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from ranger.api.commands import *
import os
import shutil


class toggle_termplug(Command):
"""
:toggle_termplug
"""

def execute(self):
p = not self.fm.settings["_termplug"]
self.fm.settings["_termplug"] = p
self.fm.execute_console(f"termplug {'%f' if p else ''}")
status = f"termplug {'active' if p else 'off'}"
self.fm.notify(status, duration=4)


class termplug(Command):
"""
:termplug
"""

def execute(self):
do_preview = self.fm.settings["_termplug"]
termplug = shutil.which("termplug")
try:
f = self.rest(1)
if not do_preview:
self.fm.execute_console(f"shell -s termplug --exit")
elif not termplug:
self.fm.notify(f"termplug script not found")
elif os.path.isfile(f):
self.fm.notify(f"preview {f}")
self.fm.execute_console(f"shell -s termplug '{f}'")
except Exception as e:
self.fm.notify(e)
19 changes: 19 additions & 0 deletions ranger/plugins/termplug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ranger.api
import os
import sys

old_hook_init = ranger.api.hook_init


def hook_init(fm):
def on_move(signal):
if fm.thisfile and fm.settings["_termplug"] and signal.new:
f = signal.new.path
fm.execute_console(f"termplug {f}")

fm.settings["_termplug"] = False
fm.signal_bind("move", on_move)
return old_hook_init(fm)


ranger.api.hook_init = hook_init

0 comments on commit 78cfc2d

Please sign in to comment.