Skip to content

Instantly share code, notes, and snippets.

@Makaze
Forked from vn-ki/Instructions.md
Created February 24, 2024 19:33
Show Gist options
  • Save Makaze/2e911b051d5e439a2703f0c19e381951 to your computer and use it in GitHub Desktop.
Save Makaze/2e911b051d5e439a2703f0c19e381951 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 """
filename = self.arg(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 dh chrome_choose .
map dn console chrome_choose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment