/fff

📁 A simple file manager written in bash.

Primary LanguageShellMIT LicenseMIT

List of Modifications

  • Added a config file (~/.fff) and removed globals
  • Made f_color1 have priority over di from LS_COLORS
  • Added f_visual_default to allow prioritizing EDITOR over VISUAL
  • Added f_print_actions to toggle printing file operations so you can look back at them after exiting
  • Added f_trash_confirm to allow not asking for confirmation when trashing files (I don't know why this wasn't added when the default option isn't to permanently delete)
  • Added fkey_img_preview_max to preview images at maximum size
  • Formatted in hard tabs with spaces for alignment instead of 4-wide soft tabs
  • Added fkey_open_vim to open in vi/m instead of VISUAL/EDITOR
  • Added fkey_duplicate and fkey_duplicate_all to duplicate files
  • Added visual mode, for easier selection
  • Added fkey_bulk_execute and fkey_bulk_execute_all to run commands on selected files
  • Improved keypress recognition; eg. Ctrl+Left won't mark all for deletion because the escape sequence ends with D
  • Improved image viewing (actions used to close will happen, and if it was a movement fff will attempt to show the newly highlighted item)
  • Made image viewing and stats viewing update on size change
  • Made image viewing refresh on focus regained, so that switching between WM tabs does not hide image sometimes.

fff (Fucking Fast File-Manager)

img

A simple file manager written in bash.

  • It's Fucking Fast 🚀
  • Minimal (almost only requires bash and coreutils)
  • Smooth Scrolling (using vim keybindings)
  • Works on Linux, BSD, macOS, Haiku etc.
  • Supports LS_COLORS!
  • File Operations (copy, paste, cut, ranger style bulk rename, etc) img
  • Instant as you type search
  • Tab completion for all commands!
  • Automatic CD on exit (see setup)
  • Works as a file picker in vim/neovim (link)!
  • Display images with w3m-img!
  • Supports $CDPATH.

Table of Contents

Dependencies

  • bash 3.2+
  • coreutils
    • File operations.
  • find (optional)
    • duplicate
  • xdg-utils (optional)
    • Program handling (non-text).
    • Not needed on macos and Haiku.
    • Customizable (if not using xdg-open): $f_opener.

Dependencies for image display

  • w3m-img
  • xdotool for X
  • fbset for the framebuffer

(Un)installation

  1. Download fff
  2. Add to $PATH

NOTE: fff can be uninstalled by - duh - deleting it, and the only other places anything is stored are .cache/fff and .local/share/fff in your $HOME by default, or whatever you've set XDG_CACHE_HOME and XDG_DATA_HOME to.

CD on Exit

Bash and Zsh

# Add this to your .bashrc, .zshrc or equivalent
# fff will run with 'fff' or 'f' (or whatever you decide to name the function)
f() {
    \fff "$@"
    cd "$(cat "${XDG_CACHE_HOME:=${HOME}/.cache}/fff/.fff_d" 2>/dev/null)"
    rm "${XDG_CACHE_HOME:=${HOME}/.cache}/fff/.fff_d" 2>/dev/null
}
alias fff='f'

Fish

# Add this to you config.fish or equivalent.
# Fish don't support recursive calls so use f function
function f
    fff $argv
    set -q XDG_CACHE_HOME; or set XDG_CACHE_HOME $HOME/.cache
    cd (cat $XDG_CACHE_HOME/fff/.fff_d)
end

Usage

j: scroll down
k: scroll up
h: go to parent dir
l: go to child dir

enter: go to child dir
backspace: go to parent dir

-: Go to previous dir.

g: go to top
G: go to bottom

:: go to a directory by typing.

.: toggle hidden files
/: search
t: go to trash
~: go to home
R: refresh current dir
!: open shell in current dir

x: view file/dir attributes
i: display image with w3m-img
I: display image with w3m-img at maximum size

down:  scroll down
up:    scroll up
left:  go to parent dir
right: go to child dir

f: new file
n: new dir
r: rename
X: toggle executable

y: mark copy
a: mark duplicate
m: mark move
d: mark trash ([~/.local/share/fff or whatever you've set XDG_DATA_HOME to]/trash/)
s: mark symbolic link
b: mark bulk rename
e: mark bulk execute

Y: mark all for copy
A: mark all for duplicate
M: mark all for move
D: mark all for trash ([~/.local/share/fff or whatever you've set XDG_DATA_HOME to]/trash/)
S: mark all for symbolic link
B: mark all for bulk rename
E: mark all for bulk execute

v: open file in vi/m (instead of VISUAL/EDITOR)
V: toggle visual mode
p: paste/move/delete/bulk_rename
c: clear file selections and close visual mode

[1-9]: favourites/bookmarks (see customization)

q: exit (with 'cd' if enabled)
Ctrl+C: exit without 'cd'

Customization

This is the list of settings along with their default values. You only need to modify the keybindings that you'd like to change from the default. fff will run perfectly fine without any of these defined.

# Try VISUAL before EDITOR when opening text files or those without a mime_type
f_visual_default=1

# Print actions so you can look back at what you did if needed after exiting
f_print_actions=1

# Ask for confirmation when moving items to trash
# You can accidentally permanently delete if you set f_trash_cmd to rm or equivalent, be careful!
f_trash_confirm=1

# Use LS_COLORS to color fff (if set)
f_LS_COLORS=1

# Show/Hide hidden files on open
# (On by default)
f_show_hidden=0

# For color numbers, see http://www.linux-sxs.org/housekeeping/lscolors.html 30-37

# Directory color [0-7]
f_color1=2

# Status background color [0-7]
f_color2=1

# Selection color [0-7] (copied/moved files)
f_color3=1

# Cursor color [0-7]
f_color4=6

# Status foreground color [0-7]
f_color5=0

# Text Editor, you'll have to set these as environment variables in .bashrc or equivalent
# vi is fallback if neither is set
# See f_visual_default
export VISUAL="vi"
export EDITOR="vi"

# File Opener
f_opener="xdg-open"

# Enable or disable CD on exit
f_cd_on_exit=1

# CD on exit helper file
# Default: '${XDG_CACHE_HOME}/fff/fff.d'
#          If not using XDG, '${HOME}/.cache/fff/fff.d' is used
f_cd_file

# Trash Directory
# Default: '${XDG_DATA_HOME}/fff/trash'
#          If not using XDG, '${XDG_DATA_HOME}/fff/trash' is used
f_trash_dir

# Trash Command
# Default (unset, passing anything prevents using default) uses 'mv'
# The program will be passed the list of selected files and directories
f_trash_cmd=

# Favourites (Bookmarks) (keys 1-9) (dir or file)
f_fav1=
f_fav2=
f_fav3=
f_fav4=
f_fav5=
f_fav6=
f_fav7=
f_fav8=
f_fav9=

# w3m-img offsets
f_w3m_offset_x=0
f_w3m_offset_y=0

# File format
# Customize the item string
# Format ('%f' is the current file): "str%fstr"
# Example (Add a tab before files): f_file_format="\t%f"
f_file_format="%f"

# Mark format
# Customize the marked item string
# Format ('%f' is the current file): "str%fstr"
# Example (Add a ' >' before files): f_mark_format="> %f"
f_mark_format=" %f*"

Customizing the keybindings

Keybindings

This is the list of keybindings along with their default values. You only need to modify the keybindings that you'd like to change from the default. fff will run perfectly fine without any of these defined.

### Moving around

# Go to child directory
fkey_child1="l"
fkey_child2=$'\e[C' # Right Arrow
fkey_child3=""      # Enter / Return

# Go to parent directory
fkey_parent1="h"
fkey_parent2=$'\e[D' # Left Arrow
fkey_parent3=$'\177' # Backspace
fkey_parent4=$'\b'   # Backspace (Older terminals)

# Go to previous directory
fkey_previous="-"

# Search
fkey_search="/"

# Spawn a shell
fkey_shell="!"

# Scroll down
fkey_scroll_down1="j"
fkey_scroll_down2=$'\e[B' # Down Arrow

# Scroll up
fkey_scroll_up1="k"
fkey_scroll_up2=$'\e[A'   # Up Arrow

# Go to top and bottom
fkey_top="g"
fkey_bottom="G"

# Go to dirs
fkey_go_dir=":"
fkey_go_home="~"
fkey_go_trash="t"
fkey_refresh="R"

### File operations

fkey_yank="y"
fkey_move="m"
fkey_trash="d"
fkey_link="s"
fkey_duplicate="a"
fkey_bulk_rename="b"
fkey_bulk_execute="e"

fkey_yank_all="Y"
fkey_move_all="M"
fkey_trash_all="D"
fkey_link_all="S"
fkey_duplicate_all="A"
fkey_bulk_rename_all="B"
fkey_bulk_execute_all="E"

fkey_paste="p"
fkey_clear="c"

fkey_rename="r"
fkey_mkdir="n"
fkey_mkfile="f"

# Open with vi/m instead of VISUAL/EDITOR
fkey_open_vim="v"

# Toggle visual mode (not to be confused with VISUAL)
# Default is 'V' over 'v' because in other programs 'v' is open in vi/m
fkey_toggle_visual="V"

# Display image with w3m-img
fkey_image_preview="i"
# Display image with w3m-img at maximum size
fkey_image_preview_max="I"

### Miscellaneous

# Show file attributes
fkey_view_attributes="x"

# Toggle executable flag
fkey_toggle_executable="X"

# Toggle hidden files
fkey_toggle_show_hidden="."

Disabling keybindings.

You can't unset keybindings by making their value ''. What you need to do is change their value to off.

Example:

# go_trash was bound to 't', now its unset
fkey_go_trash="off"

# mkfile is now set to 't' and its original
# keybinding of 'f' is also unset
fkey_mkfile="t"

Dealing with conflicting keybindings

When rebinding a key in fff make sure you don't have two bindings with the same value. You can avoid this by setting the other conflicting key-binding to something else or by changing its value to off.

How to figure out special keys

Below is a tiny script which will tell you the exact value to use. It automates the deciphering of special key escape sequences to the exact value fff needs. Save this to a file and run it (or just paste in a terminal). Give it a key-press and it'll spit out the exact value needed.

#!/usr/bin/env bash
# Output the key-binding values for 'fff'
key() {
    case "$1" in
        # Backspace
        $'\b'|$'\177')
            printf '%s\n' "key: \$'\\b' or \$'\\177'"
        ;;

        # Escape Sequences
        $'\e')
            read -rsn 2
            printf '%s %q\n' "key:" "${1}${REPLY}"
        ;;

        # Return / Enter
        "")
            printf '%s\n' "key: \" \""
        ;;

        # Everything else
        *)
            printf '%s %q\n' "key:" "$1"
        ;;
    esac
}

read -srn 1 && key "$REPLY"

Using fff in vim/neovim as a file picker

See: fff.vim

Why?

¯\(ツ)