literate-dotfiles/ranger.org

779 lines
21 KiB
Org Mode
Raw Normal View History

2021-01-03 22:52:53 +01:00
#+TITLE: Ranger
2021-01-01 20:12:34 +01:00
#+SETUPFILE: ./setup/org-setup-file.org
2019-01-31 09:41:03 +01:00
* Documentation
2020-05-26 10:35:01 +02:00
#+begin_quote
%f the highlighted file
%d the path of the current directory
%s the selected files in the current directory
%t all tagged files in the current directory
%c the full paths of the currently copied/cut files
%p the full paths of selected files
#+end_quote
2019-01-31 09:41:03 +01:00
* Config
:PROPERTIES:
:header-args: :tangle ~/.config/ranger/rc.conf
:header-args+: :comments both :mkdirp yes
:END:
2019-01-31 09:41:03 +01:00
** Options
#+BEGIN_SRC conf
# Which viewmode should be used? Possible values are:
# miller: Use miller columns which show multiple levels of the hierarchy
# multipane: Midnight-commander like multipane view showing all tabs next
# to each other
set viewmode miller
# How many columns are there, and what are their relative widths?
2019-08-23 09:59:15 +02:00
set column_ratios 1,1
2019-01-31 09:41:03 +01:00
# Which files should be hidden? (regular expression)
set hidden_filter ^\.|\.(?:pyc|vrb|pyo|lof|bak|swp|aux|log|nav|out|snm|toc|bcf|run\.xml|synctex\.gz|blg|bbl)$|^lost\+found$|^__(py)?cache__$
# Show hidden files? You can toggle this by typing 'zh'
set show_hidden false
# Ask for a confirmation when running the "delete" command?
# Valid values are "always", "never", "multiple" (default)
# With "multiple", ranger will ask only if you delete multiple files at once.
set confirm_on_delete multiple
# Which script is used to generate file previews?
# ranger ships with scope.sh, a script that calls external programs (see
# README.md for dependencies) to preview images, archives, etc.
2020-03-01 17:58:07 +01:00
set preview_script /home/thomas/.config/ranger/scope.sh
2019-01-31 09:41:03 +01:00
# Use the external preview script or display simple plain text or image previews?
set use_preview_script true
# Automatically count files in the directory, even before entering them?
set automatically_count_files true
# Open all images in this directory when running certain image viewers
set open_all_images true
# Be aware of version control systems and display information.
set vcs_aware false
# Use one of the supported image preview protocols
set preview_images true
# Set the preview image method
set preview_images_method ueberzug
2019-01-31 09:41:03 +01:00
2019-06-22 17:33:15 +02:00
set colorscheme default
2019-01-31 09:41:03 +01:00
# Preview files on the rightmost column?
# And collapse (shrink) the last column if there is nothing to preview?
set preview_files true
set preview_directories true
set collapse_preview true
# Draw the status bar on top of the browser window (default: bottom)
set status_bar_on_top false
# Draw a progress bar in the status bar which displays the average state of all
# currently running tasks which support progress bars?
set draw_progress_bar_in_status_bar true
# Draw borders around columns?
set draw_borders true
# Display the directory name in tabs?
set dirname_in_tabs false
# Enable the mouse support?
set mouse_enabled true
# Display the file size in the main column or status bar?
set display_size_in_main_column true
2020-03-01 17:58:07 +01:00
set display_size_in_status_bar false
2019-01-31 09:41:03 +01:00
# Display files tags in all columns or only in main column?
2020-03-01 17:58:07 +01:00
set display_tags_in_all_columns false
2019-01-31 09:41:03 +01:00
# Set a title for the window?
set update_title false
# Set the title to "ranger" in the tmux program?
2020-03-01 17:58:07 +01:00
set update_tmux_title true
2019-01-31 09:41:03 +01:00
# Shorten the title if it gets long? The number defines how many
# directories are displayed at once, 0 turns off this feature.
set shorten_title 3
# Abbreviate $HOME with ~ in the titlebar (first line) of ranger?
set tilde_in_titlebar true
# How many directory-changes or console-commands should be kept in history?
set max_history_size 20
set max_console_history_size 50
# Try to keep so much space between the top/bottom border when scrolling:
set scroll_offset 8
# Flush the input after each key hit? (Noticeable when ranger lags)
set flushinput true
# Padding on the right when there's no preview?
# This allows you to click into the space to run the file.
set padding_right true
set autosave_bookmarks false
set autoupdate_cumulative_size false
# Turning this on makes sense for screen readers:
set show_cursor false
# One of: size, natural, basename, atime, ctime, mtime, type, random
set sort natural
# Additional sorting options
set sort_reverse false
set sort_case_insensitive true
set sort_directories_first true
set sort_unicode false
# Enable this if key combinations with the Alt Key don't work for you.
# (Especially on xterm)
set xterm_alt_key false
# Whether to include bookmarks in cd command
set cd_bookmarks false
# Avoid previewing files larger than this size, in bytes. Use a value of 0 to
# disable this feature.
2020-03-01 17:58:07 +01:00
set preview_max_size 5000000
2019-01-31 09:41:03 +01:00
# Add the highlighted file to the path in the titlebar
set show_selection_in_titlebar true
# The delay that ranger idly waits for user input, in milliseconds, with a
# resolution of 100ms. Lower delay reduces lag between directory updates but
# increases CPU load.
set idle_delay 2000
# When the metadata manager module looks for metadata, should it only look for
# a ".metadata.json" file in the current directory, or do a deep search and
# check all directories above the current one as well?
set metadata_deep_search false
# Clear all existing filters when leaving a directory
set clear_filters_on_dir_change false
# Disable displaying line numbers in main column
set line_numbers false
#+END_SRC
** Command Aliases in the Console
#+BEGIN_SRC conf
alias q quit
alias filter scout -prt
alias find scout -aeit
alias mark scout -mr
alias unmark scout -Mr
alias search scout -rs
alias search_inc scout -rts
alias travel scout -aefiklst
#+END_SRC
** Some Custom Keybindings
2021-10-25 14:31:23 +02:00
Extract:
2019-01-31 09:41:03 +01:00
#+BEGIN_SRC conf
map ,x shell ~/.config/ranger/scripts/extract.sh %f
2019-01-31 09:41:03 +01:00
#+END_SRC
2021-10-25 14:31:23 +02:00
Compress:
2019-01-31 09:41:03 +01:00
#+BEGIN_SRC conf
map ,z shell ~/.config/ranger/scripts/compress.sh %f
2019-01-31 09:41:03 +01:00
#+END_SRC
2021-10-25 14:31:23 +02:00
Get Bibtex from PDF:
2019-01-31 09:41:03 +01:00
#+BEGIN_SRC conf
map ,b shell pdf2bib %f
#+END_SRC
2021-10-25 14:31:23 +02:00
Convert images/pdf/...:
2019-12-15 10:52:03 +01:00
#+BEGIN_SRC conf
2021-02-10 17:58:41 +01:00
map ,c shell convert-file %f
2019-12-15 10:52:03 +01:00
#+END_SRC
2021-10-25 14:31:23 +02:00
Open SXIV on current directory:
#+BEGIN_SRC conf
map ,s shell nohup sxiv -t %d &
#+END_SRC
2021-10-25 14:31:23 +02:00
Upload to https://0x0.st/:
#+BEGIN_SRC conf
map ,t shell upload %f
2019-01-31 09:41:03 +01:00
#+END_SRC
2021-10-25 14:31:23 +02:00
Open current folder with PCManFM:
2020-05-26 08:36:47 +02:00
#+begin_src conf
map ,o shell nohup pcmanfm %d &
2020-05-26 08:36:47 +02:00
#+end_src
2021-10-25 14:31:23 +02:00
Print on Rnice:
2020-05-26 08:36:47 +02:00
#+BEGIN_SRC conf
map ,p shell print-rnice %f &
2020-05-26 08:36:47 +02:00
#+END_SRC
2021-10-25 14:31:23 +02:00
Backup to NAS:
2020-05-26 10:35:01 +02:00
#+BEGIN_SRC conf
map ,B shell ~/.config/ranger/scripts/backup-to-nas.sh %s &
2020-05-26 10:35:01 +02:00
#+END_SRC
2021-10-25 14:31:23 +02:00
#+begin_src conf
map ,y shell ~/.config/ranger/scripts/copy-content.sh %s &
#+end_src
2020-05-26 08:36:47 +02:00
** Scripts
*** Extract Script
:PROPERTIES:
2020-05-26 08:36:47 +02:00
:header-args: :tangle ~/.config/ranger/scripts/extract.sh
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
if [ $TMUX ]; then
2021-11-03 10:58:41 +01:00
tmux split -v -l 2 atool -x "$1" && tmux select-pane -U
else
2021-11-03 10:58:41 +01:00
atool -x "$1"
fi
#+end_src
2020-05-26 08:36:47 +02:00
*** Compress Script
:PROPERTIES:
:header-args: :tangle ~/.config/ranger/scripts/compress.sh
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
if [ $TMUX ]; then
2021-11-03 10:58:41 +01:00
tmux split -v -l 2 apack "${1%.*}.zip" "$1" && tmux select-pane -U
else
2021-11-03 10:58:41 +01:00
apack "${1%.*}.zip" "$1"
fi
2019-12-15 10:52:03 +01:00
#+end_src
2020-03-01 17:58:07 +01:00
2021-10-25 14:31:23 +02:00
*** Copy File Content
:PROPERTIES:
:header-args: :tangle ~/.config/ranger/scripts/copy-content.sh
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
2021-11-03 10:58:41 +01:00
xclip -sel c < "$1" && dunstify "Ranger" "Copied to clipboard"
2021-10-25 14:31:23 +02:00
#+end_src
*** TODO [#B] Backup to NAS
2020-05-26 10:35:01 +02:00
:PROPERTIES:
:header-args: :tangle ~/.config/ranger/scripts/backup-to-nas.sh
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
- Arguments are the files to be backup to the NAS
#+begin_src bash
if [ $TMUX ]; then
2021-10-25 14:31:23 +02:00
tmux split -v -l 2 rsync -a --inplace --info=progress2 --rsh='ssh ' "$@" homelab:/srv/storage/Backups/ && tmux select-pane -U
else
2021-10-25 14:31:23 +02:00
rsync -a --info=progress2 --inplace --rsh='ssh' "$@" homelab:/srv/storage/Backups/
fi
2020-05-26 10:35:01 +02:00
#+end_src
*** Paste with Rsync
:PROPERTIES:
:header-args: :tangle ~/.config/ranger/scripts/paste-rsync.sh
:header-args+: :comments both :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
- First argument is the directory where to copy files
- All other arguments are files that are to be copied
#+begin_src bash
if [ $TMUX ]; then
tmux split -v -l 1 rsync -a --info=progress2 "${@:2}" "$1" && tmux select-pane -U
else
rsync -a --info=progress2 "${@:2}" "$1"
fi
2020-05-26 10:35:01 +02:00
#+end_src
2019-01-31 09:41:03 +01:00
** Define keys for the browser
*** Basic
#+BEGIN_SRC conf
map Q quit!
map q eval fm.execute_console("shell tmux detach") if 'TMUX' in os.environ.keys() else fm.execute_console("quit")
2020-03-01 17:58:07 +01:00
#+END_SRC
2019-01-31 09:41:03 +01:00
2020-03-01 17:58:07 +01:00
#+BEGIN_SRC conf
map <C-c> abort
map <esc> change_mode normal
map ~ set viewmode!
2020-03-01 17:58:07 +01:00
#+END_SRC
2019-01-31 09:41:03 +01:00
2020-03-01 17:58:07 +01:00
#+BEGIN_SRC conf
map ? help
2020-03-01 17:58:07 +01:00
#+END_SRC
2019-01-31 09:41:03 +01:00
2020-03-01 17:58:07 +01:00
#+BEGIN_SRC conf
map : console
map ; console
2020-03-01 17:58:07 +01:00
#+END_SRC
#+BEGIN_SRC conf
map ! console shell%space
2020-03-01 17:58:07 +01:00
#+END_SRC
#+BEGIN_SRC conf
map @ console -p6 shell %%s
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Open Shell in current directory
#+BEGIN_SRC conf
map s shell $SHELL
map S shell nohup $TERMINAL &
2019-01-31 09:41:03 +01:00
#+END_SRC
2020-03-01 17:58:07 +01:00
*** Open With
2019-07-12 13:26:03 +02:00
#+BEGIN_SRC conf
map O chain draw_possible_programs; console open_with%space
2019-07-12 13:26:03 +02:00
#+END_SRC
2019-01-31 09:41:03 +01:00
*** Filter
#+BEGIN_SRC conf
map f console filter%space
# Reset filter
map F filter
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Tagging / Marking
#+BEGIN_SRC conf
map <Space> mark_files toggle=True
map v mark_files all=True toggle=True
2019-01-31 09:41:03 +01:00
#+END_SRC
*** VIM-like
#+BEGIN_SRC conf
copymap <UP> k
copymap <DOWN> j
copymap <LEFT> h
copymap <RIGHT> l
copymap <HOME> gg
copymap <END> G
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Jumping around
#+BEGIN_SRC conf
map H history_go -1
map L history_go 1
2020-03-01 17:58:07 +01:00
#+END_SRC
#+BEGIN_SRC conf
map ] move_parent 1
map [ move_parent -1
2020-03-01 17:58:07 +01:00
#+END_SRC
#+BEGIN_SRC conf
map } traverse
2019-01-31 09:41:03 +01:00
#+END_SRC
#+BEGIN_SRC conf
map cd console cd%space
2020-03-01 17:58:07 +01:00
#+END_SRC
2019-05-16 21:13:08 +02:00
2020-03-01 17:58:07 +01:00
*** Go to special folders
#+BEGIN_SRC conf
map gh cd ~/
map gb cd ~/Cloud/brain
map gm cd ~/Cloud/thesis
map gp cd ~/Pictures
2021-10-25 14:31:23 +02:00
map gP cd ~/Cloud/pictures/phone
map gT cd ~/.local/share/Trash/files
map gd cd ~/Downloads
map gc cd ~/Cloud
map gV cd ~/.config/literate-dotfiles
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Get size of folders
#+BEGIN_SRC conf
# Get size of all folders
map du shell -p du --max-depth=1 -h --apparent-size
# Get size of all folders and sort them
map dU shell -p du --max-depth=1 -h --apparent-size | sort -rh
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Yank path of directory/file
#+BEGIN_SRC conf
# Yank path of current directory/file
map yp shell -f echo -n %d/%f | xsel -i; xsel -o | xsel -i -b
# Yank path of directory
map yd shell -f echo -n %d | xsel -i; xsel -o | xsel -i -b
# Yank filename
map yn shell -f echo -n %f | xsel -i; xsel -o | xsel -i -b
2019-01-31 09:41:03 +01:00
#+END_SRC
2019-06-22 17:33:15 +02:00
*** Drag and Drop
#+BEGIN_SRC conf
map D shell dragon-drag-and-drop -a -x %p
2019-06-22 17:33:15 +02:00
#+END_SRC
2020-03-01 17:58:07 +01:00
*** Rename files
2019-01-31 09:41:03 +01:00
#+BEGIN_SRC conf
map a rename_append
map C eval fm.execute_console("bulkrename") if fm.thisdir.marked_items else fm.open_console("rename ")
map A eval fm.open_console('rename ' + fm.thisfile.relative_path.replace("%", "%%"))
map I eval fm.open_console('rename ' + fm.thisfile.relative_path.replace("%", "%%"), position=7)
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Paste files
#+BEGIN_SRC conf
map pp paste
map po paste overwrite=True
map pP paste append=True
map pO paste overwrite=True append=True
map pl paste_symlink relative=False
map pL paste_symlink relative=True
map phl paste_hardlink
map pht paste_hardlinked_subtree
2019-01-31 09:41:03 +01:00
#+END_SRC
2020-05-26 10:35:01 +02:00
Paste with Rsync
#+BEGIN_SRC conf
map pr shell ~/.config/ranger/scripts/paste-rsync.sh %d %c
2020-05-26 10:35:01 +02:00
#+END_SRC
2019-01-31 09:41:03 +01:00
*** Delete and move files
#+BEGIN_SRC conf
map dD shell -s trash-put %s
map dd cut
map du uncut
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Copy files
#+BEGIN_SRC conf
map yy copy
map yu uncut
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Searching
#+BEGIN_SRC conf
map / console search%space
map n search_next
map N search_next forward=False
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Tabs
#+BEGIN_SRC conf
map <C-n> tab_new ~
map <C-w> tab_close
2020-03-01 17:58:07 +01:00
map <TAB> tab_move 1
map <S-TAB> tab_move -1
2020-03-01 17:58:07 +01:00
map gn tab_new ~
map gt tab_move 1
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Settings
#+BEGIN_SRC conf
map zh set show_hidden!
2020-03-01 17:58:07 +01:00
map zi set preview_images!
map zv set use_preview_script!
2019-01-31 09:41:03 +01:00
#+END_SRC
*** Bookmarks
#+BEGIN_SRC conf
map `<any> enter_bookmark %any
map '<any> enter_bookmark %any
map m<any> set_bookmark %any
map um<any> unset_bookmark %any
2019-01-31 09:41:03 +01:00
map m<bg> draw_bookmarks
copymap m<bg> um<bg> `<bg> '<bg>
2019-01-31 09:41:03 +01:00
#+END_SRC
2020-03-01 17:58:07 +01:00
*** FZF
2019-01-31 09:41:03 +01:00
#+BEGIN_SRC conf
map <C-f> fzf_select
2019-01-31 09:41:03 +01:00
#+END_SRC
** Define keys for the console
*** Basic
#+BEGIN_SRC conf
cmap <tab> eval fm.ui.console.tab()
cmap <s-tab> eval fm.ui.console.tab(-1)
2021-10-25 14:31:23 +02:00
2019-01-31 09:41:03 +01:00
cmap <ESC> eval fm.ui.console.close()
2021-10-25 14:31:23 +02:00
2019-01-31 09:41:03 +01:00
cmap <CR> eval fm.ui.console.execute()
2021-10-25 14:31:23 +02:00
2019-01-31 09:41:03 +01:00
cmap <C-l> redraw_window
copycmap <ESC> <C-c>
copycmap <CR> <C-j>
#+END_SRC
*** Move around
#+BEGIN_SRC conf
cmap <up> eval fm.ui.console.history_move(-1)
cmap <down> eval fm.ui.console.history_move(1)
cmap <left> eval fm.ui.console.move(left=1)
cmap <right> eval fm.ui.console.move(right=1)
#+END_SRC
*** Line Editing
#+BEGIN_SRC conf
cmap <backspace> eval fm.ui.console.delete(-1)
cmap <delete> eval fm.ui.console.delete(0)
cmap <C-w> eval fm.ui.console.delete_word()
cmap <C-y> eval fm.ui.console.paste()
copycmap <home> <C-a>
copycmap <end> <C-e>
#+END_SRC
* Rifle
:PROPERTIES:
2021-10-25 14:31:23 +02:00
:CUSTOM_ID: rifle
:header-args: :tangle ~/.config/ranger/rifle.conf
:header-args+: :comments both :mkdirp yes
:END:
2019-01-31 09:41:03 +01:00
2021-10-25 14:31:23 +02:00
** Documentation
#+BEGIN_SRC conf :tangle no
# This is the configuration file of "rifle", ranger's file executor/opener.
# Each line consists of conditions and a command. For each line the conditions
# are checked and if they are met, the respective command is run.
#
# Syntax:
# <condition1> , <condition2> , ... = command
#
# The command can contain these environment variables:
# $1-$9 | The n-th selected file
# $@ | All selected files
#
# If you use the special command "ask", rifle will ask you what program to run.
#
# Prefixing a condition with "!" will negate its result.
# These conditions are currently supported:
# match <regexp> | The regexp matches $1
# ext <regexp> | The regexp matches the extension of $1
# mime <regexp> | The regexp matches the mime type of $1
# name <regexp> | The regexp matches the basename of $1
# path <regexp> | The regexp matches the absolute path of $1
# has <program> | The program is installed (i.e. located in $PATH)
# env <variable> | The environment variable "variable" is non-empty
# file | $1 is a file
# directory | $1 is a directory
# number <n> | change the number of this command to n
# terminal | stdin, stderr and stdout are connected to a terminal
# X | $DISPLAY is not empty (i.e. Xorg runs)
#
# There are also pseudo-conditions which have a "side effect":
# flag <flags> | Change how the program is run. See below.
# label <label> | Assign a label or name to the command so it can
# | be started with :open_with <label> in ranger
# | or `rifle -p <label>` in the standalone executable.
# else | Always true.
#
# Flags are single characters which slightly transform the command:
# f | Fork the program, make it run in the background.
# | New command = setsid $command >& /dev/null &
# r | Execute the command with root permissions
# | New command = sudo $command
# t | Run the program in a new terminal. If $TERMCMD is not defined,
# | rifle will attempt to extract it from $TERM.
# | New command = $TERMCMD -e $command
# Note: The "New command" serves only as an illustration, the exact
# implementation may differ.
# Note: When using rifle in ranger, there is an additional flag "c" for
# only running the current file even if you have marked multiple files.
2021-10-25 14:31:23 +02:00
#+END_SRC
2021-10-25 14:31:23 +02:00
** Text Files
Define the =$EDITOR= for text files as first action:
#+BEGIN_SRC conf
mime ^text, label editor = $EDITOR -- "$@"
mime ^text, label pager = "$PAGER" -- "$@"
2021-10-25 14:31:23 +02:00
#+END_SRC
2021-10-25 14:31:23 +02:00
Favorite editors:
#+begin_src conf
mime ^text, has nvim, flag f = nvim "$@"
mime ^text, has emacsclient, X, flag f = emacsclient -c "$@"
#+end_src
2021-10-25 14:31:23 +02:00
Org mode files
#+BEGIN_SRC conf
ext org, has emacsclient, X, flag f = emacsclient -c "$@"
#+END_SRC
#+BEGIN_SRC conf
!mime ^text, label editor, ext xml|json|csv|tex|py|pl|rb|js|sh|php = $EDITOR -- "$@"
!mime ^text, label pager, ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@"
ext py = python -- "$1"
ext pl = perl -- "$1"
ext rb = ruby -- "$1"
ext js = node -- "$1"
ext sh = sh -- "$1"
ext php = php -- "$1"
2021-10-25 14:31:23 +02:00
#+END_SRC
2021-10-25 14:31:23 +02:00
** PDF, Epub and jdvu
#+BEGIN_SRC conf
ext pdf, has zathura, X, flag f = zathura -- "$@"
ext pdf, has mupdf, X, flag f = mupdf "$@"
ext pdf, X, flag f = "$BROWSER" "$@"
#+END_SRC
#+BEGIN_SRC conf
ext epub, has zathura, X, flag f = zathura -- "$@"
ext epub, has mupdf, X, flag f = mupdf "$@"
#+END_SRC
#+BEGIN_SRC conf
ext djvu, has zathura, X, flag f = zathura -- "$@"
ext djvu, has evince, X, flag f = evince -- "$@"
ext djvu, has atril, X, flag f = atril -- "$@"
#+END_SRC
** Archives
#+BEGIN_SRC conf
ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has atool = atool -- "$@" | "$PAGER"
ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has atool = atool -- "$@" | "$PAGER"
ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has aunpack = aunpack -- "$@"
ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has aunpack = aunpack -- "$@"
ext tar|gz, has tar = tar vvtf "$@" | "$PAGER"
ext tar|gz, has tar = tar vvxf "$@"
2021-10-25 14:31:23 +02:00
#+END_SRC
2021-10-25 14:31:23 +02:00
** Websites
#+BEGIN_SRC conf
ext x?html?, has qutebrowser, X, flag f = qutebrowser -- "$@"
ext x?html?, has firefox, X, flag f = firefox -- "$@"
ext x?html?, has elinks, terminal = elinks "$@"
ext x?html?, has w3m, terminal = w3m "$@"
#+END_SRC
** Word, Excel and Presentation files
#+BEGIN_SRC conf
ext docx?, has onlyoffice, X, flag f = onlyoffice "$@"
ext docx?, has wps, X, flag f = wps "$@"
ext docx?, has libreoffice, X, flag f = libreoffice "$@"
#+END_SRC
2021-10-25 14:31:23 +02:00
#+begin_src conf
ext pptx?, has onlyoffice, X, flag f = onlyoffice "$@"
ext pptx?, has wps, X, flag f = wps "$@"
ext pptx?, has libreoffice, X, flag f = libreoffice "$@"
#+end_src
#+begin_src conf
ext csv|xlsx?, has sc-im = sc-im -- "$@"
ext csv|xlsx?, has onlyoffice, X, flag f = onlyoffice "$@"
ext csv|xlsx?, has wps, X, flag f = wps "$@"
ext csv|xlsx?, has libreoffice, X, flag f = libreoffice "$@"
#+end_src
** Images
#+BEGIN_SRC conf
mime ^image/svg, has inkview, X, flag f = inkview -- "$@"
mime ^image/svg, has inkscape, X, flag f = inkscape -- "$@"
mime ^image/svg, has display, X, flag f = display -- "$@"
#+END_SRC
#+BEGIN_SRC conf
mime ^image/gif, has mpv, X, flag f = mpv --loop -- "$@"
mime ^image/gif, has qutebrowser, X, flag f = qutebrowser -- "$@"
#+END_SRC
#+BEGIN_SRC conf
mime ^image, has sxiv, X, flag f = sxiv -- "$@"
mime ^image, has feh, X, flag f = feh --scale-down --auto-zoom -- "$@"
#+END_SRC
** Audio
#+BEGIN_SRC conf
mime ^audio|ogg$, terminal, has mpv = mpv --no-audio-display -- "$@"
mime ^audio|ogg$, X, flag f, has vlc = vlc -- "$@"
#+END_SRC
** Video
#+BEGIN_SRC conf
mime ^video, has mpv, X, flag f = mpv -- "$@"
mime ^video, has vlc, X, flag f = vlc -- "$@"
#+END_SRC
** Misc
#+BEGIN_SRC conf
ext 1 = man "$1"
ext s[wmf]c, has zsnes, X = zsnes "$1"
ext s[wmf]c, has snes9x-gtk,X = snes9x-gtk "$1"
ext nes, has fceux, X = fceux "$1"
ext exe = wine "$1"
name ^[mM]akefile$ = make
#+END_SRC
#+BEGIN_SRC conf
# Define the editor for non-text files + pager as last action
!mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = ask
label editor, !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = $EDITOR -- "$@"
label pager, !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@"
has dragon-drag-and-drop, X, flag f = dragon-drag-and-drop -a -x "$@"
2019-01-31 09:41:03 +01:00
#+END_SRC
2019-12-15 10:52:03 +01:00
2019-01-31 09:41:03 +01:00
* Ranger Commands
:PROPERTIES:
:header-args: :tangle ~/.config/ranger/commands.py
:header-args+: :comments both :mkdirp yes
:END:
2019-01-31 09:41:03 +01:00
** Import
#+begin_src python
from ranger.api.commands import *
2019-01-31 09:41:03 +01:00
import os
2019-01-31 09:41:03 +01:00
#+end_src
** fzf_select
#+begin_src python
class fzf_select(Command):
"""
:fzf_select
Find a file using fzf.
With a prefix argument select only directories.
See: https://github.com/junegunn/fzf
"""
def execute(self):
import subprocess
import os.path
if self.quantifier:
# match only directories
command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m"
else:
# match files and directories
command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-o -print 2> /dev/null | sed 1d | cut -b3- | fzf +m"
fzf = self.fm.execute_command(command, universal_newlines=True, stdout=subprocess.PIPE)
stdout, stderr = fzf.communicate()
if fzf.returncode == 0:
fzf_file = os.path.abspath(stdout.rstrip('\n'))
if os.path.isdir(fzf_file):
self.fm.cd(fzf_file)
else:
self.fm.select_file(fzf_file)
2019-01-31 09:41:03 +01:00
#+end_src
2021-10-25 14:31:23 +02:00