Skip to content
Arijit Basu edited this page Sep 2, 2021 · 145 revisions

This section is slowly moving to https://arijitbasu.in/xplr/en/awesome-plugins.html#integration

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 of init.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.

Spawn multiple sessions in different tabs (iTerm2)

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
    ]] },
  },
}

Bookmark

Bookmark files using m and fuzzy search bookmarks using backtick.

Expand for details

xplr-bookmark.gif

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

Persistent, multi-session bookmark

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 history

Fuzzy search the last visited directories.

Expand for details
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

Batch rename the selected or visible files and directories in $PWD.

Expand for details

xplr-rename.gif

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

Serve $PWD

Serve $PWD using a static web server via LAN.

Expand for details

xplr-serve765d076f20239d9d.gif

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

Organize files (f2)

Organize the files under $PWD.

Expand for details

xplr-f2.gif

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

Back to: Features

Clone this wiki locally