GithubHelp home page GithubHelp logo

wprobot / rexply Goto Github PK

View Code? Open in Web Editor NEW

This project forked from renatofrota/rexply

0.0 1.0 0.0 174 KB

reXply is a handy tool to copy/paste replies and scripts with an advanced front-matter system for variables substitutions and dynamic per-template settings, bash script processing/evaluation, and much more, that can also be used as a launcher to other scripts/executables!

License: GNU General Public License v3.0

Shell 100.00%

rexply's Introduction

reXply

reXply is a handy tool to copy/paste replies and scripts with an advanced front-matter system for variables substitutions and dynamic per-template settings, bash script processing/evaluation, and much more, that can also be used as a launcher to other scripts/executables!

Current version

v0.1.6 - View changelog

Dependencies

  • dmenu and/or yad
  • xclip and/or xsel and/or pbcopy+pbpaste
  • xdotool (optional but strongly recommended)

More info regarding these dependencies at the end of this file.

How to install

  1. install as more dependencies as you can on your system (recommended: dmenu, yad, xclip, xdotool)
  2. clone this repo
  3. symlink the binary in a folder in your $PATH

If you are unsure, just copy and paste on your terminal (the script will try to install the dependencies - if you're using Linux):

cd ~/ && \
git clone https://github.com/renatofrota/rexply.git && \
rexplylink=$(echo $PATH|cut -d: -f1)/rexply && \
{ [ ! -f $rexplylink ] && sudo ln -s ~/rexply/rexply.bash $rexplylink ; }; \
[ ! -f $(echo $PATH|cut -d: -f1)/rexply ] && echo problem creating symlink || \
echo "all done! now assign a keybinding to call 'rexply' on your O.S. ;)"

Upgrading

  1. download and extract the zip or clone the repo to an alternative location
  2. copy everything over your existing install (except rexply.cfg)

If you are unsure, just copy and paste on your terminal:

OLD_IFS=$IFS && IFS=$'\n' && cd ~/ && echo -n "Downloading..." && \
wget -q -O rexply.zip https://github.com/renatofrota/rexply/archive/master.zip && \
echo -en "\nExtracting..." && sleep 1 && unzip -q -o rexply.zip && mkdir -p rexply && \
echo -en "\nCopying over..." && sleep 1 && for dir in $(find rexply-master/ -type d); \
do mkdir -p "$(echo $dir | sed 's,^rexply-master,rexply,')"; done && \
for file in $(find rexply-master -type f ! -name rexply.cfg); \
do cp "$file" "$(echo $file | sed 's,^rexply-master,rexply,')"; done && \
echo && read -rep "Reinstall rexply.cfg file? [y/n]: " -n 1 reinstall && \
{ if [[ "$reinstall" =~ (1|y|Y|s|S) ]]; then cp rexply-master/rexply.cfg rexply/; fi ; } && \
rm -rf rexply-master rexply.zip && echo "All done!" && IFS=$OLD_IFS

Operation

It works from command line (terminal) - just type in 'rexply'.

But it is only 1% as useful as it could be by running it this way. To feel the power:

  1. add the custom command rexply to your Keyboard shortcuts/keybindings area;
  2. bind a key to the custom command you've created
  3. go to an editor, browser, or any other text area field
  4. press the binded key and be amazed!

Make it dance in your rhythm

The default replies/scripts repository is $HOME/rexply/rexply-data/repository.

You can just create more folders/files there (or change default repository in rexply.cfg).

The files can be:

  • regular text files
  • text with dynamic questions
  • front-matter powered templates
  • "evaluated" (processed with eval)
  • bash scripts (executable scripts - preferably with #!/bin/bash hashbang)
  • or any other binary/executable script/application (after enabling $execute)

Text files

No secrets on this. I just recommend you append .txt to the file names so your editors do not try to apply syntax highlighting based on file contents.

Dynamic questions

You can add questions that will be dynamically replaced during text processing.

Hello, {{?Friend's name?}}! How are you going today?

When pasting this template, you will be asked "Friend's name?" (the last ? is not part of dynamic questions syntax, it's part of the question itself).

Front-matter powered templates

Create a section with some variables at the top of the file (surround the variables by --- above and below) and use them within template text in format ${varname}. Example:

---
#vartype:varname!Field Label:default value
#field label and default value are optional
entry:customer!Customer name:
txt:code!Code used to fix
num:minutes!Time to take effect (in minutes):10!0..20!5
---
Hello ${customer},

Thanks for getting in touch with us.

To resolve this problem I've added this code to [b]public_html/.htaccess[/b] file on your account:

[code]${code}[/code]

This change should reflect in aproximately ${minutes} minutes.

@

When inserting this template, reXply will ask you to provide the data to the 3 variables:

  • your customer's name
  • the code you've used to resolve his problem
  • how many minutes it will take to reflect on his end

After the variable name, you can add : and the default input for that variable. When no default is provided, variable name will be the default. To make default empty just add : and nothing else in front of it.

If using dmenu, you will see an empty field with a 'selection' below (the default input). You can type any value or just hit enter to use the pre-selected option. One field at a time. Optionally, a preview of all the fields can be displayed underneath the selector ($preview='1').

If using yad, a form will be displayed, with all fields visible and editable simultaneously. Each field is pre-filled with the default value data (or the variable name, if you have set no default value). Numeric fields will have +/- buttons - and may be limited to the range you have defined. In the example above !0..20!5 means "a value between 0 to 20, in steps of 5". The "steps" are only for the +/- buttons (or up/down arrows): any value within the allowed range can be manually entered.

Oh, and the @ at the end is to confirm you want the 2 blank lines processed (any @ at the very end of the template is removed during processing - if $checkpt is enabled, or -k 1 is passed). Without it, the 2 lines would be discarded.

Variables syntax

The syntax for a front-matter variable is vartype:varname[!var label][:][default value], where:

  1. vartype - variable type (see types below) - mandatory
  2. varname - the name of the variable (used to perform the substitutions in template file) - mandatory
  3. var label - the label that is displayed in Dmenu/Yad forms that field
  4. the colon sign - to indicate a default value follows
  5. default value - the default value for the variable

The last 3 are optional.

Data variables types

Currently, 5 types of data variables are supported

  1. entry, field, var or text - single line input field
  2. txt or textarea - multiline (textarea) input field
  3. num or numeric - a field that only allow numbers [ with a default value [ a defined range of accepted values [ and a default stepping ] ] ] (num:varname[:default[!MIN..MAX[!STEP]]])
    • a default is specified as usual: num:minutes:10
    • an accepted range is specific by appending !MIN..MAX (e.g.: num:minutes:10!0..20)
    • the stepping comes after, also separated by ! (e.g.: num:minutes:10!0..20!5)
    • note: the acceptance of these settings depends on the application you use to process front-matter vars ($yadform or -Y parameter)
      • yad
        • accepts all parameters
        • the visual +/- buttons and up/down keyboard arrows respect the range and stepping
        • you can still manually type a value out of the range and/or disrespecting the stepping
      • dmenu
        • takes the default value
        • discard all the rest
  4. select or selectbox - a field with a list of pre-defined values displayed as a selectbox item
  5. combo or combobox - like select field, but allows a custom value to be entered

Keeping variables untouched

You may want to display a ${variable} in it's literal form (when it's part of the final command you want to run after template is processed). There are 2 ways to do this:

  1. add an entry variable and set the default value to the variable string: entry:variable:${variable}
    • it will be displayed during front-matter processing - and you can override it (as any entry var)
  2. use the special front-matter command keep: keep:variable
    • it won't be displayed during front-matter processing

Note: variables in format $variable (without {}) are parsed as environment variables (they will "disappear" when pasting a template if they do not exist on your environment). Always use ${variable} format (with {}).

Front-matter overrides variables

3 special front-matter variables can be used to override reXply options. Note: they must come before regular variables.

They accept 0/1, like the config vars themselves, aliases like true/false, yes/no, and some others (check rexply.bash code if you're curious).

  1. yadform or editor (overrides $yadform)
  2. preview (accepts 0,1,2)
  3. runeval

Specifics of each form-filling utility

  • dmenu:
    • Enter submit selection or input.
    • Shift+enter to submit input.
    • Ctrl+y to paste primary X selection ("mouse highlight")
    • Ctrl+Y to paste clipboard
  • yad:
    • Regular shortcuts (enter submit, tab change field)
    • On multiline textareas, ctrl+tab to change field
    • You cannot use | in provided data as it will break the field<->data association

Comments within front-matter header

---
field:var_name:default value#this is a comment (variable is processed)
#this line is also a comment. this method or above are valid and recommended
this line is not a comment but parsing will fail: 'this' is not a valid variable type
---

Front-matter tips:

  1. you can type \\n while filling in front-matter variables data - reXply will convert these to line breaks when pasting the data to your application.
  2. the preview lines (those displayed below dmenu when $yadform='0' (-Y 0), while processing a file with front-matter variables) are "filtered" as you type - and will eventually disappear: as soon as your data input do not match any of them. If it is a problem for you (you ends up selecting an existing item when trying to insert a data with shorter lenght to the next fields) you can resolve by one of the methods below ("it's simple, I will disable preview in config", you may think at first - yes, it works, but there are several smarter ways to "fix" it without taking it hard):
    • use shift+return to submit to send your current input instead selected item
    • disable preview specifically for that template, by adding preview:false to it's front-matter;
    • change the order of variables in the front-matter (place variables that expects a shorter input at the top);

Template evaluation (passing them through eval)

You can add bash subshells $() on your file. These will be executed (with your homedir as their initial working directory) and their output will replace the subshell dynamically in the template (just like as any command you run in a terminal window).

Environment variables like ${USER}, ${PWD}, etc are also replaced even when outside $()

Note: some consider eval dangerous (have you ever heard eval is evil?) so environment vars and front-matter vars substitutions are made using just envsubst by default - if you want to go evil way, I mean.. eval way, enable eval by setting $runeval='1', passing -E 1 parameter, or add runeval:true to template front-matter).

Bash scripts

They are executed when selected in the menu and you have execution permissions over the file (chmod +x path/to/filename.bash).

Be careful. Your homedir is the initial working directory when you start reXply using a keybinding. When running from command line, the working dir is kept.

Please note:

  1. if the file is not executable, no matter the extension, it will be processed as a regular text template.
  2. the files are not executed directly by default ($execute='0'), they are called through bash, like this: bash <file>.
  3. If you enable $execute or pass -X 1 the file will be executed direcly, making reXply act as a truly and independent "launcher" for your applications/scripts.

I recommend you add #!/bin/bash hashbang at the top of the file and use .bash or .sh extension so your text editors also know they are shell executable files - and they keep being properly executed if you enable $execute.

More information

reXply will, by default:

  • hide directories and files preceded by a dot (e..g: .filename) - $showall='0'
  • disallow browsing to parent directories outside it's default repository - $breakit='0'
  • hide form list any file bigger than a pre-defined size limit (default: 3MB) - $maxsize='3'
  • prevent execution of arbitrary executables (call executables using bash $filename) - $bashit='1'

All these restrictions are due to security concerns and can be modified by either:

  • modifying the rexply file directly ($HOME/rexply/rexply.bash); or
  • modifying the additional config file ($HOME/rexply/rexply.cfg)

We will avoid updating the additional config file but take your backups before updating, please.

To-do

  • test if everything works in OSX (help wanted)
  • improve textarea fields (the pipe char | currently breaks field<->data associations)
  • provide a way to create new files with front-matter headers using the script itself
  • buy more coffee (please donate below!)

More info regarding the dependencies

  • dmenu is the standard application used to output information and capture input due to it's more widespread presence - including availability on OSX via Homebrew, etc. If you want more fancy visual, with screen-centered dialogs, ability to fill in all front-matter variables of a template in a single - floating window - form, set options $yadfile (file selection) and $yadform (front-matter form) to 1 (or run rexply -y 1 -Y 1) so you can use yad instead.
  • xclip may be substituted with xsel (see $copycmd option) or pbcopy and pbpaste - useful in OSX, I just had no time to test yet, so it may need some polishing.
  • xdotool is used to handle the window focus (and apparently, it's not that easy to make it work on OSX due to XTEST not being active by default). You can get rid of this dependency by disabling $focusit option. A possible problem if you are using the script to paste data (with xclip or xsel) while another window is set as 'always-on-top': the data will sometimes end up being pasted to the window set as 'always-on-top' instead the desired window (depends on the application and other circumstances - not tested on OSX yet).

OSX

xdotool is used to paste in Linux by default. In OSX, the default is no automatic pasting and using pbcopy/pbpaste instead ($pasteit='0' and $copycmd='3'). The processed data should be on your clipboard, just paste it manually after running reXply.

If you want to try automatic pasting, there are 2 ways to implement it:

  1. set $pastedefault='eval cat $1' and $pasteterminal='eval cat $1' (or just pass -P 'eval cat $1' parameter) - note the single quotes - and pipe reXply to whichever program you want to use to handle the data in sequence. Just as an example, at least theoretically, piping the output to pbcopy (e.g.: rexply -P 'eval cat $1' | pbcopy) the data will be copied to clipboard (as reXply does by default) and you can paste it manually. I could not test (pbcopy not available in my Linux distro and xclip/xsel handles input buffer a bit differently). Feel free to try this and other ways to parse the output :)
  2. there's another option: disable automatic pasting with $pasteit='0' (what is default for OSX) and also set it to keep the tmpfile after processed ($deltemp='0' or -d 0), then use the processed data saved at tmpfile (by default, $HOME/rexply/rexply-data/.tmp/tmp) by your own way.

Donate

Help me keep my stuff Open Source and free.

Think on how much time($) you're saving with this tool and buy me some coffee! :)

USD

Donate

BRL

Doar

rexply's People

Contributors

renatofrota avatar

Watchers

 avatar

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.