Files
dotfiles/.bash/.bash_vifm
2025-11-19 15:56:21 +01:00

104 lines
2.7 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
[[ $(command -v crossSession) ]] || source "$BASH_DOTFILES/.bash_aliases"
vifm() {
\cat <<- "HELP"
Use bash build-in:
- cd (ch dir), ls or tree (list), find
- mkdir (make dir), touch (make file), rm (remove)
- cp (copy), mv (move+rename)
- cat (print file), head (print first lines), tail (print last lines)
- ln (link), chmod (change perm), chown (change owner)
- file/dir info: stat , file , mimetype
- cd stack: pushd, popd, dirs -v
Use helpers:
- rsync (copy), fd (verbo-less find)
- m (marks, `cd "$m<name>"`), cd-kdialog
- trash-* (trash)
Use bash/terminal features:
- history search (`cd`)
- tab completion
- substitution: `!#:`, `!!:`
- globbing: `*`, `?`, `{}``for file in *; do; done`
Use GUI:
- open . or open <file/dir>
- dolphin
Use VIM:
- ls > <batch>.sh → vim <batch>.sh → :wq → bash <batch>.sh
Use vim aliases?:
- y (yank), p (paste), P (paste and clear)
- y [file(s)|dir(s)]; p | xargs -I{} <cp|mv|…> {}; P
Use `$PROMPT_COMMAND`:
- `PROMPT_COMMAND+='; ls -A'; PROMPT_COMMAND="${PROMPT_COMMAND/; ls -A}"`
HELP
}
m(){
if [[ '-d' == "$1" ]]; then
unset "m$2"
crossSession "m$2"
return 0
fi
if [[ -z "$1" ]]; then
printenv | grep -e '^m' | sort | xargs -I{} echo \${}
return 0
fi
if [[ "--help" == "$1" ]]; then
\cat <<- "HELP"
m [--help]
Lists all marks or print this help.
m -d <name>
Deletes mark <name>. Unsets variable and cross session variable.
m <name> [path]
Sets mark <name> to current directory or [path].
The mark is just a bash variable, use `$m<name>`.
cd $m<name>
cd to mark <name>.
HELP
return 0
fi
local n="m$1"
[[ -z "${!n}" ]] || return 1
[[ -z "$2" ]] && local p="$(pwd)" || local p="$(readlink -f $2)"
crossSession "$n" "$p"
export $n="$p"
}
alias cd-kdialog='cd "$(kdialog --getexistingdirectory --title "Vyberte složku" 2>/dev/null)"'
alias fd='fdfind'
# vim-like aliases?
alias dw='rm'
alias cw='mv'
alias g='fdfind'
# yanked files
export YANKED=()
p() {
for f in "${YANKED[@]}"; do
IFS=$'' echo "$f"
done
} # p | xargs -I{} …
P() { YANKED=(); echo 'YANKED=()'; }
y() {
local pwd="$(pwd)"
if [[ -z "$1" ]]; then
YANKED=("$pwd")
else
for f in "$@"; do
if [[ "$f" == /* ]]; then
YANKED+=("$f")
elif [[ "$f" == ./* || "$f" == '.' ]]; then
YANKED+=("$pwd${f:1}")
else
YANKED+=("$pwd/$f")
fi
done
fi
echo $(p)
}
# tab completion
[[ $(command -v _complete_alias) ]] || source "$BASH_DOTFILES/complete-alias/complete_alias"
\. <(fdfind --gen-completions)
complete -F _complete_alias fd
complete -F _complete_alias dw
complete -F _complete_alias cw
complete -F _complete_alias g