-
-
Notifications
You must be signed in to change notification settings - Fork 79
Hacks
Here's a list of hacks that you can just copy-paste in your config file. Though, some of them might require specific binaries to be installed.
If you have some hacks to add, please share them here.
To start creating your own , visit the fzf integration tutotial.
NOTE: Anywhere I mention fzf, you can replace it with the finder of your choice (e.g. skim, fzy).
IMPORTANT: With
v0.10.*
release,config.yml
has been deprecated in favor ofinit.lua
. Hence, although, the underlying data structure is mostly the same, the syntax needs to be converted to Lua. I have created xplr-yml2lua to help with the migration. It can (partially) convert YAML string into flat/nested Lua tables.
Overwrite the default search functionality with fuzzy search.
Expand for details
- Author: @sayanarijit
- Requires: fzf, pistol
- Tested on: Linux
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-f"] = {
help = "search with preview",
messages = {
{
BashExec = [===[
PTH=$(cat "${XPLR_PIPE_DIRECTORY_NODES_OUT:?}" | awk -F / '{print $NF}' | fzf --preview "pistol '{}'")
if [ -d "$PTH" ]; then
echo ChangeDirectory: "'"$PWD/${PTH:?}"'" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo FocusPath: "'"$PWD/${PTH:?}"'" >> "${XPLR_PIPE_MSG_IN:?}"
fi
]===]
},
},
}
Spawn multiple xplr
sessions in different windows.
Works perfectly with this hack.
Expand for details
- Author: @sayanarijit
- Requires: alacritty
- Tested on: Linux
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-n"] = {
help = "new session",
messages = {
{ BashExecSilently = [===[
alacritty --command xplr &
]===] },
},
}
Creating a new session that starts with iTerm2.
Expand for details
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-n"] = {
help = "new session",
messages = {
{ BashExecSilently = [[
osascript <<EOF
tell application "iTerm2"
tell current window
create tab with default profile
tell current session to write text "xplr"
end tell
end tell
]] },
"Refresh",
},
}
Copy the selected or focused file to the system clipboard using yy
and paste using p
.
Works perfectly with this hack.
Expand for details
- Author: @sayanarijit
- Requires: xclip
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
y:
help: copy
messages:
- PopMode
- SwitchModeCustom: copy
p:
help: paste
messages:
- BashExecSilently: |
xclip-pastefile > /dev/null && echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}"
custom:
copy:
name: copy
key_bindings:
on_key:
y:
help: copy focused file
messages:
- BashExecSilently: |
xclip-copyfile $(cat "${XPLR_PIPE_RESULT_OUT:?}")
- PopMode
esc:
help: cancel
messages:
- PopMode
Bookmark files using m
and fuzzy search bookmarks using backtick.
Expand for details
- Author: @sayanarijit
- Requires: fzf
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
m:
help: bookmark
messages:
- BashExecSilently: |
PTH="${XPLR_FOCUS_PATH:?}"
if echo "${PTH:?}" >> "${XPLR_SESSION_PATH:?}/bookmarks"; then
echo "LogSuccess: ${PTH:?} added to bookmarks" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: Failed to bookmark ${PTH:?}" >> "${XPLR_PIPE_MSG_IN:?}"
fi
'`':
help: go to bookmark
messages:
- BashExec: |
PTH=$(cat "${XPLR_SESSION_PATH:?}/bookmarks" | fzf --no-sort)
if [ "$PTH" ]; then
echo FocusPath: "'"${PTH:?}"'" >> "${XPLR_PIPE_MSG_IN:?}"
fi
Fuzzy search the last visited directories.
Expand for details
- Author: @sayanarijit
- Requires: fzf
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
ctrl-h:
help: history
messages:
- BashExec: |
PTH=$(cat "${XPLR_PIPE_HISTORY_OUT:?}" | sort -u | fzf --no-sort)
if [ "$PTH" ]; then
echo ChangeDirectory: "'"${PTH:?}"'" >> "${XPLR_PIPE_MSG_IN:?}"
fi
Batch rename the selected or visible files and directories in $PWD.
Expand for details
- Author: @sayanarijit
- Requires: pipe-rename
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
R:
help: batch rename
messages:
- BashExec: |
SELECTION=$(cat "${XPLR_PIPE_SELECTION_OUT:?}")
NODES=${SELECTION:-$(cat "${XPLR_PIPE_DIRECTORY_NODES_OUT:?}")}
if [ "$NODES" ]; then
echo -e "$NODES" | renamer
echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}"
fi
Expand for details
Share the selected or focused files or receive files in $PWD via QR code on LAN.
- Author: @sayanarijit
- Requires: qrcp
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
Q:
help: send/receive via QR
messages:
- SwitchModeCustom: qrcp
custom:
qrcp:
name: qrcp
key_bindings:
on_key:
s:
help: send
messages:
- BashExec: |
qrcp send --keep-alive -- $(cat "${XPLR_PIPE_RESULT_OUT:?}")
r:
help: receive
messages:
- BashExec: |
qrcp receive --keep-alive
esc:
help: cancel
messages:
- PopMode
Serve $PWD using a static web server via LAN.
Expand for details
- Author: @sayanarijit
- Requires: sfz, fzf
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
S:
help: serve $PWD
messages:
- BashExec: |
IP=$(ip addr | grep -w inet | cut -d/ -f1 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | fzf --prompt 'Select IP > ')
echo "IP: ${IP:?}"
read -p "Port (default 5000): " PORT
echo
sfz --all --cors --no-ignore --bind ${IP:?} --port ${PORT:-5000} . &
sleep 1 && read -p '[press enter to exit]'
kill -9 %1
Get the disk usage of the files under $PWD.
Expand for details
- Author: @sayanarijit
- Requires: ncdu
- Tested on: Linux
xplr.config.modes.builtin.default.key_bindings.on_key.D = {
help = "new session",
messages = {
{ BashExec = "ncdu" },
"ClearScreen",
},
}
Get the disk usage of the files under $PWD.
Expand for details
- Author: @sayanarijit
- Requires: dua-cli
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
D:
help: disk usage
messages:
- BashExec: |
dua i
- ClearScreen
Get the disk usage of the files under $PWD.
Expand for details
- Author: @sayanarijit
- Requires: diskonaut
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
D:
help: disk usage
messages:
- BashExec: |
diskonaut
- ClearScreen
paste.rs integration
Paste files to paste.rs, open and delete using fuzzy search.
Expand for details
- Author: @sayanarijit
- Requires: fzf, sd, curl
- Tested on: Linux
modes:
custom:
paste.rs:
name: paste.rs
key_bindings:
on_key:
p:
help: paste
messages:
- BashExec: |
PTH=$(basename "${XPLR_FOCUS_PATH:?}")
DEST="${XPLR_SESSION_PATH:?}/paste.rs.list"
curl --data-binary "@${PTH:?}" "https://paste.rs" | tee -a "${DEST:?}"
echo
read -p "[enter to continue]"
- PopMode
l:
help: list
messages:
- BashExec: |
cat "${XPLR_SESSION_PATH:?}/paste.rs.list"
echo
read -p "[enter to continue]"
- PopMode
o:
help: search and open
messages:
- BashExec: |
DEST="${XPLR_SESSION_PATH:?}/paste.rs.list"
URL=$(fzf --preview "curl -s '{}'" < "${DEST:?}")
if [ "$URL" ]; then
OPENER=$(which xdg-open)
${OPENER:-open} "${URL:?}"
fi
- PopMode
d:
help: search and delete
messages:
- BashExec: |
DEST="${XPLR_SESSION_PATH:?}/paste.rs.list"
URL=$(fzf --preview "curl -s '{}'" < "${DEST:?}")
if [ "$URL" ]; then
curl -X DELETE "${URL:?}"
sd "${URL:?}\n" "" "${DEST:?}"
echo
read -p "[enter to continue]"
fi
- PopMode
esc:
help: cancel
messages:
- PopMode
builtin:
default:
key_bindings:
on_key:
P:
help: paste.rs
messages:
- PopMode
- SwitchModeCustom: paste.rs
Organize the files under $PWD.
Expand for details
- Author: @sayanarijit
- Requires: f2
- Tested on: Linux
modes:
builtin:
default:
key_bindings:
on_key:
O:
help: organize files
messages:
- PopMode
- SwitchModeCustom: f2
custom:
f2:
name: f2
key_bindings:
on_key:
u:
help: dry run undo
messages:
- BashExec: |
f2 -u
read -p '[press enter to continue]'
- PopMode
U:
help: undo
messages:
- BashExecSilently: |
f2 -u -x
- ExplorePwdAsync
b:
help: dry run org books
messages:
- BashExec: |
f2 -F -r '{{xt.Title}} by {{xt.Creator}}{{ext}}'
read -p '[press enter to continue]'
B:
help: org books
messages:
- BashExecSilently: |
f2 -F -r '{{xt.Title}} by {{xt.Creator}}{{ext}}' -x
- ExplorePwdAsync
m:
help: dry run org music
messages:
- BashExec: |
f2 -F -f '(\d+).*' -r '{{id3.artist}}/{{id3.album}}/$1-{{id3.title}}{{ext}}'
read -p '[press enter to continue]'
M:
help: org music
messages:
- BashExecSilently: |
f2 -F -f '(\d+).*' -r '{{id3.artist}}/{{id3.album}}/$1-{{id3.title}}{{ext}}' -x
- ExplorePwdAsync
i:
help: dry run org images
messages:
- BashExec: |
f2 -F -r '{{x.dt.YYYY}}/{{x.dt.MMM}}-{{x.dt.DD}}-{{x.dt.YYYY}}_{{x.dt.H}}-{{x.dt.mm}}-{{x.dt.ss}}_{{x.make}}-{{x.model}}{{ext}}'
read -p '[press enter to continue]'
I:
help: org images
messages:
- BashExecSilently: |
f2 -F -r '{{x.dt.YYYY}}/{{x.dt.MMM}}-{{x.dt.DD}}-{{x.dt.YYYY}}_{{x.dt.H}}-{{x.dt.mm}}-{{x.dt.ss}}_{{x.make}}-{{x.model}}{{ext}}' -x
- ExplorePwdAsync
esc:
help: cancel
messages:
- PopMode
Jump to any directory using zoxide. autojump can be used as well, by replacing the zoxide command with 'PTH=$(autojump -s | tac | awk 'NR>7{print $2}' | fzf)'.
Expand for details
xplr.config.modes.builtin.default.key_bindings.on_key.Z = {
help = "zoxide jump",
messages = {
{ BashExec = [===[
PTH=$(zoxide query -i)
if [ "$PTH" ]; then
echo ChangeDirectory: "'"${PTH:?}"'" >> "${XPLR_PIPE_MSG_IN:?}"
fi
]===] }
}
}