Skip to content

Instantly share code, notes, and snippets.

@the-anonymous-raven
Forked from vn-ki/Instructions.md
Last active February 29, 2024 13:47
Show Gist options
  • Save the-anonymous-raven/cbf1a0c082914896aee0e735afe10517 to your computer and use it in GitHub Desktop.
Save the-anonymous-raven/cbf1a0c082914896aee0e735afe10517 to your computer and use it in GitHub Desktop.
Use ranger as chrome file chooser
#!/bin/sh
XDG_CURRENT_DESKTOP=KDE google-chrome-beta $@
import os
import sys
from ranger.core.loader import CommandLoader
from ranger.api.commands import Command
class chrome_choose(Command):
def execute(self):
""" Extract copied files to current directory """
s = ""
for word in range(1, len(self.args)):
s += self.arg(word)
s += " "
filename = s[0 : len(s) - 1]
cwd = self.fm.thisdir
if filename == '.':
with open('/tmp/ranger-chrome-choosed', 'w') as f:
f.write(cwd.path + '/')
sys.exit(0)
with open('/tmp/ranger-chrome-choosed', 'w') as f:
f.write(os.path.join(cwd.path, filename))
sys.exit(0)

Use ranger as chrome file chooser

  1. Copy the contents of kdialog to /usr/local/bin/kdialog
  2. Copy the contents of chrome_chooser.py to ~/.config/ranger/plugins/chrome_chooser.py
  3. Optionally map appropriately
  4. Run chrome with XDG_CURRENT_DESKTOP=KDE
#!/bin/sh
for ((i=1;i<=$#;i++));
do
if [ ${!i} = "--getsavefilename" ]
then ((i++))
filename=${!i};
fi
if [ ${!i} = "--version" ]
then
echo "someversion"
exit
fi
done;
path=$( echo ${filename%/*} )
file=$( echo ${filename##/*/} )
rm /tmp/ranger-chrome-choosed
termite -e "ranger" -t file-chooser-ranger
selected=$(cat /tmp/ranger-chrome-choosed 2> /dev/null)
if [ ! $? = 0 ]
then
exit 1
fi
if [ -d $selected ]
then
echo "$selected$file"
else
echo $selected
fi
map d. chrome_choose .
map ds chrome_choose %s
Copy link

ghost commented Feb 29, 2024

How do I open with Chromium?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment