Git Product home page Git Product logo

map.xplr's Introduction

map.xplr

Visually inspect and interactively execute batch commands using xplr

Basic Demo

map-xplr.mp4

Oraganize Files

map-xplr-organize.mp4

Visually inspect and interactively execute batch commands using xplr. It's like xargs.xplr but better.

Tip: This plugin can be used with find.xplr.

Requirements

None

Installation

Install manually

  • Add the following line in ~/.config/xplr/init.lua

    local home = os.getenv("HOME")
    package.path = home
    .. "/.config/xplr/plugins/?/init.lua;"
    .. home
    .. "/.config/xplr/plugins/?.lua;"
    .. package.path
  • Clone the plugin

    mkdir -p ~/.config/xplr/plugins
    
    git clone https://github.com/sayanarijit/map.xplr ~/.config/xplr/plugins/map
  • Require the module in ~/.config/xplr/init.lua

    require("map").setup()
    
    -- Or
    
    local map = require("map")
    map.setup{
      mode = "default",  -- or `xplr.config.modes.builtin.default`
      key = "M",
      editor = os.getenv("EDITOR") or "vim",
      editor_key = "ctrl-o",
      prefer_multi_map = false,
      placeholder = "{}",
      spacer = "{_}",
      custom_placeholders = map.placeholders,
    }
    
    -- Type `M` to switch to single map mode.
    -- Then press `tab` to switch between single and multi map modes.
    -- Press `ctrl-o` to edit the command using your editor.

Placeholders

Apart from {}, the primary placeholder and {_}, the spacer, you can also use the following placeholders:

  • {idx}: 0-based index of the node.
  • {0idx}: 0-padded, 0-based index of the node.
  • {num}: 1-based index of the node.
  • {0num}: 0-padded, 1-based index of the node.
  • {total}: Total number of nodes.
  • {abs}: Absolute path of the node.
  • {rel}: Relative path of the node.
  • {name}: Name of the node.
  • {ext}: Extension of the node.
  • {mime}: Mime essence of the node.
  • {size}: Size of the node.
  • {perm}: Permissions of the node in octal.
  • {rwx}: Permissions of the node in rwx.
  • {dir}: Parent directory of the node.
  • {uid}: User ID of the node.
  • {gid}: Group ID of the node.
  • {cdate}: Creation date of the node in YYYY-MM-DD.
  • {ctime}: Creation time of the node in HH:MM:SS.
  • {mdate}: Last modification date of the node in YYYY-MM-DD.
  • {mtime}: Last modification time of the node in HH:MM:SS.

Custom Placeholders

You can add new custom placeholders, or modify the existing ones via the placeholders table.

It is just a function function(node, meta) that takes the following arguments and returns a string.

node

See the official documentation.

meta

It contains the following fields:

  • total: Total count of the nodes being operated on (used in {total}).
  • index: 0-based index of the node (used in {idx}, {0idx}, {num}, {0num}).

Example

local map = require("map")

-- Add custom placeholders
map.placeholders["{created}"] = function(node, meta)
  return xplr.util.shell_quote(os.date("%Y-%m-%d@%H:%M:%S", node.created / 1000000000))
end

-- Alternatively, compose existing placeholders
map.placeholders["{modified}"] = function(node, meta)
  local d = map.placeholders["{mdate}"](node, meta)
  local t = map.placeholders["{mtime}"](node, meta)
  return d .. "@" .. t
end

Features

  • All the great features from xargs.xplr.
  • File paths will be auto quoted.
  • Press tab to easily switch map mode without losing any context.
  • Press ctrl-o to open the command in your editor.
  • Visually inspect and interactively edit commands.
  • Use placeholder {} and spacer {_} to format commands in multi map mode.
  • Use custom placeholders for custom file properties.
  • Interactive placeholder suggestion.

map.xplr's People

Contributors

richardhttps avatar sayanarijit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

map.xplr's Issues

Request: add an index/counter placeholder

Would be cool to have an {idx} placeholder for every iteration.

So you could do mv {} file-{idx}.{ext} and rename everything to the same name with a number.

Additionally, and I don't know how much this would complicate things, having a left-padded, offset adjustable, incrementing counter would be ideal.

For example, if you know you're looping through 987 files, you'd ideally want a 3 character long counter starting at 001 and ending on 987. Maybe something like {idx+X, Y} where idx = iteration, X = custom offset (simple addition to the counter) and Y is the length of the string to 0-pad to. So {idx+3, 5} would give 00003, 00004, ... 09876 and so on.

A spacer placeholder

Implement {_}, a placeholder, that will add a spacer between two columns to help formatting multi map commands.

Date format issue

[2023-07-31 8:31:09.732144189 +00:00:00] ERROR   runtime error: ...anarijit/.local/share/xplr/sayanarijit/map.xplr/init.lua:126: bad argument #2 to 'date' (number has no integer representati
on)
stack traceback:
        [C]: in ?
        [C]: in function 'os.date'
        ...anarijit/.local/share/xplr/sayanarijit/map.xplr/init.lua:126: in local 'fn'
        ...anarijit/.local/share/xplr/sayanarijit/map.xplr/init.lua:160: in upvalue 'map_multi'
        ...anarijit/.local/share/xplr/sayanarijit/map.xplr/init.lua:222: in function <...anarijit/.local/share/xplr/sayanarijit/map.xplr/init.lua:209>
        (...tail calls...)

add more placeholders

Add more placeholders such as {ext} {mime} {name} etc. Can be used for organizing files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.