Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion fff
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
#
# fff - fucking fast file-manager.

msg() {
echo >&2 -e "${1-}"
}

die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}

get_os() {
# Figure out the current operating system to set some specific variables.
# '$OSTYPE' typically stores the name of the OS kernel.
Expand Down Expand Up @@ -154,9 +165,30 @@ get_mime_type() {
mime_type=$(file "-${file_flags:-biL}" "$1" 2>/dev/null)
}

create_marked_files_cache () {
touch "$marked_files_cache" || die "Could not touch $marked_files_cache ."
test -f "$marked_files_cache" || die "$marked_files_cache is not a file."
chmod 600 "$marked_files_cache" || die "Could not set chmod 0600 on $marked_files_cache ."
chown "$USER" "$marked_files_cache" || die "Could not set owner of $marked_files_cache ."
Comment on lines +169 to +172

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the terminal actually look after such error conditions? fff resets it on exit which can interfere with messages.

}

save_marked_files () {
date >> /tmp/saved
if [[ ${#marked_files[@]} -gt 0 ]]; then
flock "$marked_files_cache" printf '%s\n' "${marked_files[@]}" > "$marked_files_cache" \
|| die "Could not write to $marked_files_cache ."
else
flock "$marked_files_cache" echo -n > "$marked_files_cache" \
|| die "Could not write to $marked_files_cache ."
fi
pkill -USR1 -u "$USER" -f "^bash.*./fff"
}



status_line() {
# Status_line to print when files are marked for operation.
local mark_ui="[${#marked_files[@]}] selected (${file_program[*]}) [p] ->"
local mark_ui="[${#marked_files[@]}] selected (${file_program[*]} ${marked_files[*]}) [p] ->"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this make the status crazy long?


# Escape the directory string.
# Remove all non-printable characters.
Expand Down Expand Up @@ -185,6 +217,13 @@ status_line() {
"$LINES"
}

load_marked_files() {
date >> /tmp/load

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging to generic names. Not opt-in.

IFS=$'\r\n' GLOBIGNORE='*' command eval 'marked_files=($(< $marked_files_cache ))' \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dangerous and unnecessary eval.

Suggested change
IFS=$'\r\n' GLOBIGNORE='*' command eval 'marked_files=($(< $marked_files_cache ))' \
mapfile -t marked_files < "$marked_files_cache" \

|| die "Could not load from $marked_files_cache ."
status_line
}

read_dir() {
# Read a directory to an array and sort it directories first.
local dirs
Expand Down Expand Up @@ -887,6 +926,7 @@ key() {
${FFF_KEY_LINK:=s}|\
${FFF_KEY_BULK_RENAME:=b})
mark "$scroll" "$1"
save_marked_files
;;

# Mark all files for operation.
Expand All @@ -896,6 +936,7 @@ key() {
${FFF_KEY_LINK_ALL:=S}|\
${FFF_KEY_BULK_RENAME_ALL:=B})
mark all "$1"
save_marked_files
;;

# Do the file operation.
Expand All @@ -916,6 +957,7 @@ key() {
stty -echo

marked_files=()
save_marked_files
setup_terminal
redraw full
}
Expand All @@ -925,6 +967,7 @@ key() {
${FFF_KEY_CLEAR:=c})
[[ ${marked_files[*]} ]] && {
marked_files=()
save_marked_files
redraw
}
;;
Expand Down Expand Up @@ -1116,10 +1159,18 @@ main() {
mkdir -p "${XDG_CACHE_HOME:=${HOME}/.cache}/fff" \
"${FFF_TRASH:=${XDG_DATA_HOME:=${HOME}/.local/share}/fff/trash}"

USER=$(whoami)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't $USER defined by default? If not guaranteed, use a variable with fallback like user="${USER:-"$(whoami)"}"

# Create marked files cache.
declare -r marked_files_cache="/tmp/fff_${USER}_marked_files"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not configurable with FFF_* enc vars like other dirs.

create_marked_files_cache

# 'nocaseglob': Glob case insensitively (Used for case insensitive search).
# 'nullglob': Don't expand non-matching globs to themselves.
shopt -s nocaseglob nullglob

# Trap the USR1 signal to update status line.
trap load_marked_files USR1

# Trap the exit signal (we need to reset the terminal to a useable state.)
trap 'reset_terminal' EXIT

Expand Down