-
-
Notifications
You must be signed in to change notification settings - Fork 79
Hacks
This section is slowly moving to https://arijitbasu.in/xplr/en/awesome-plugins.html
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 Hacks, visit the fzf integration tutorial.
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
]===]
},
},
}
Delete and restore files with trash-cli. There are also notifications with terminal-notifier in both steps.
Expand for details
- Author: @lmburns
- Requires: trash-cli, terminal-notifier, fzf
- Tested on: MacOS
delkey = xplr.config.modes.builtin.delete.key_bindings.on_key
-- Trash: delete
delkey.d = {
help = "delete",
messages = {
{
BashExecSilently = [===[
while IFS= read -r line; do trash-put -- "${line:?}";
done < "${XPLR_PIPE_RESULT_OUT:?}"
echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}"
terminal-notifier -title "🗑️ File(s) deleted" -message "File(s) moved to trash"
]===],
},
"PopMode",
},
}
-- Trash: restore
delkey.r = {
help = "restore delete",
messages = {
{
BashExec = [===[
ftr; echo ExplorePwdAsync >> "${XPLR_PIPE_MSG_IN:?}"
]===],
},
"PopMode",
},
}
#!/usr/bin/env zsh
# ftr
zparseopts -D -E -a opt 'l' '-local'
if [[ "${(M)opt[@]:#-(l|-local)}" == -(l|-local) ]]; then
file="$(trash-list \
| rg --color=never "$(pwd)" \
| fzf --delimiter / --with-nth 1,-1 \
| awk '{print $3}' \
)"
else
file="$(trash-list \
| fzf --delimiter / --with-nth 1,-1 \
| awk '{print $3}' \
)"
fi
[ -n "$file" ] && yes 0 | trash-restore "$file" || exit 1
terminal-notifier -title "Trash CLI" -message "File restored"
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. Works perfectly with this hack.
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
]] },
},
}
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
A bookmark mode that allows for a bookmark file to be used throughout multiple sessions. It is set to the environment variable $XPLR_BOOKMARK_FILE
. A bookmark can be added, deleted, or jumped to.
Expand for details
-- Bookmark: mode binding
xplr.config.modes.custom.bookmark = {
name = "bookmark",
key_bindings = {
on_key = {
m = {
help = "bookmark dir",
messages = {
{ BashExecSilently = [[
PTH="${XPLR_FOCUS_PATH:?}"
if [ -d "${PTH}" ]; then
PTH="${PTH}"
elif [ -f "${PTH}" ]; then
PTH="$(dirname "${PTH}")"
fi
if echo "${PTH:?}" >> "${XPLR_BOOKMARK_FILE:?}"; then
echo "LogSuccess: ${PTH:?} added to bookmarks" >> "${XPLR_PIPE_MSG_IN:?}"
else
echo "LogError: Failed to bookmark ${PTH:?}" >> "${XPLR_PIPE_MSG_IN:?}"
fi
]] },
},
},
g = {
help = "go to bookmark",
messages = {
{
BashExec = [===[
PTH=$(cat "${XPLR_BOOKMARK_FILE:?}" | fzf --no-sort)
if [ "$PTH" ]; then
echo FocusPath: "'"${PTH:?}"'" >> "${XPLR_PIPE_MSG_IN:?}"
fi
]===]
},
},
},
d = {
help = "delete bookmark",
messages = {
{ BashExec = [[
PTH=$(cat "${XPLR_BOOKMARK_FILE:?}" | fzf --no-sort)
sd "$PTH\n" "" "${XPLR_BOOKMARK_FILE:?}"
]] },
},
},
esc = {
help = "cancel",
messages = {
"PopMode",
},
},
},
},
}
Another bookmark manager type thing, taken from wfxr's zsh plugin.
Another bookmark manager type thing, taken from wfxr's zsh plugin which has colored output with fzf.
Expand for details
xplr.config.modes.builtin.go_to.key_bindings.on_key.b = {
help = "bookmark jump",
messages = {
{ BashExec = [===[
field='\(\S\+\s*\)'
esc=$(printf '\033')
N="${esc}[0m"
R="${esc}[31m"
G="${esc}[32m"
Y="${esc}[33m"
B="${esc}[34m"
pattern="s#^${field}${field}${field}${field}#$Y\1$R\2$N\3$B\4$N#"
PTH=$(sed 's#: # -> #' "$PATHMARKS_FILE"| nl| column -t \
| gsed "${pattern}" \
| fzf --ansi \
--height '40%' \
--preview="echo {}|sed 's#.*-> ##'| xargs exa --color=always" \
--preview-window="right:50%" \
| sed 's#.*-> ##')
if [ "$PTH" ]; then
echo ChangeDirectory: "'"${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 (with selection support).
Expand for details
- Author: @sayanarijit
- Requires: dua-cli
- Tested on: Linux
xplr.config.modes.builtin.default.key_bindings.on_key.D = {
help = "disk usage",
messages = {
{
BashExec = [===[
SELECTED=$(dua i)
if [ "$SELECTED" ]; then
while read -r line; do
echo SelectPath: '"'${PWD:?}/${line:?}'"' >> "${XPLR_PIPE_MSG_IN:?}"
done <<< "$SELECTED"
fi
]===]
},
"ClearScreen",
},
}
Get the disk usage of the files under $PWD.
Expand for details
- Author: @sayanarijit
- Requires: diskonaut
- Tested on: Linux
xplr.config.modes.builtin.default.key_bindings.on_key.D = {
help = "new session",
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
]===] }
}
}