8000 GitHub - linguisticmind/fstr: Substitute placeholders in strings.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

linguisticmind/fstr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
8000
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fstr

There are times when a shell script needs to allow the user to set custom string values that may include variable content. fstr makes use of named placeholders that can be included in a string and substituted with computed values at a later point in the script.

Video tutorial:

Mindful Technology - [Bash scripting] fstr: like printf but with named placeholders and more

Support me on Ko-fi

Changelog

Version Date Description
0.1.1 2025-04-06

Substitute <override> only when command line arguments define <name> and its <replacement>.

0.1.0 2025-04-06

Initial release.

Read more

Dependencies

Essential

Essential dependencies come preinstalled on Debian Linux. Debian users may safely skip the essential dependencies section. Users of other systems have to make sure that these are installed.

Click to view

Name Notes
Bash

Developed and tested on version 5.2.15. May work with other versions, but the specified one is recommended.

Homepage: https://www.gnu.org/software/bash/

GNU coreutils

Homepage: https://www.gnu.org/software/coreutils/

GNU sed

Homepage: https://www.gnu.org/software/sed/

Required

Required dependencies must be installed in order for fstr to work.

Name Installation Notes
Lua sudo apt install lua5.4

Developed and tested on version 5.4. May work with other versions, but the specified one is recommended.

Lua's executable may be called lua5.4 or lua. The names are checked for in this order.

Homepage: https://www.lua.org/

Installation and upgrading

  1. Clone this repository to a directory of your choice (for example, ~/local/src):

    mkdir -pv ~/local/src
    cd ~/local/src
    git clone https://github.com/linguisticmind/fstr.git
  2. Symlink the shell wrapper to a directory on your PATH (for example, ~/local/bin):

    cd fstr
    ln -srv fstr ~/local/bin
    How do I add a directory to PATH?
    1. Open your ~/.bashrc file in a text editor and add the following line to end of the file:

      export PATH="$HOME/local/bin:$PATH"
    2. Restart your terminal session.

  3. Symlink the man page to a directory on your MANPATH (for example, ~/local/share/man):

    cd ~/local/src/fstr
    ln -srv man/man1/fstr.1 ~/local/share/man/man1

    Note: The man directory must contain subdirectories for different manual sections (man1, man2 etc.).

    How do I add a directory to MANPATH?
    1. Open your ~/.bashrc file in a text editor and add the following line to end of the file:

      export MANPATH="$HOME/local/share/man:$MANPATH"
    2. Restart your terminal session.

  4. To upgrade to the most recent version of fstr, run git pull in the cloned repository:

    cd ~/local/src/fstr
    git pull

Manual

FSTR(1)                     General Commands Manual                    FSTR(1)

NAME
       fstr - substitute placeholders in strings

SYNOPSIS
       fstr <str> [<name> <replacement> ...]

DESCRIPTION
       There are times when a shell script needs to allow the user to set cus‐
       tom string values that may include variable content. fstr makes use  of
       named  placeholders  that  can  be included in a string and substituted
       with computed values at a later point in the script.

       <str>  A string with placeholders.

              The placeholder format is:

              (1)    %<name>

                     or

              (2)    %{<name>:-<fallback>:+<override>}

                     :-<fallback> and :+<override> are optional and may go  in
                     any order.

              <name>  is a placeholder name to match a <name> defined via com‐
              mand line arguments. It may consist of one or more  alphanumeric
              characters and underscores.

              <fallback>  and  <override>  are  also strings with placeholders
              just like <str>.

              <fallback> is substituted if command line arguments do  not  de‐
              fine <name> and its <replacement>.

              <override>  is substituted instead of <replacement> allowing to,
              for instance, insert extra characters next to <replacement>.

              In strings with placeholders  (<str>,  <fallback>,  <override>),
              '\',  '%', '{', ':', and '}' are special characters. They can be
              escaped with backslashes ('\') to represent their  literal  val‐
              ues.

       <name> A  placeholder  name.  May  consist  of one or more alphanumeric
              characters and underscores.

       <replacement>
              A placeholder replacement. This is a  literal  string  —  unlike
              <str>,  <fallback>, and <override> which are strings with place‐
              holders.

FILES
       fstr.lua
              The main Lua script.

       fstr   A shell wrapper for 'fstr.lua'.

       tools/generate-bash-function
              Outputs a Bash function based on 'fstr.lua'.

AUTHOR
       Alex Rogers <https://github.com/linguisticmind>

HOMEPAGE
       <https://github.com/linguisticmind/fstr>

COPYRIGHT
       Copyright © 2025 Alex Rogers. License GPLv3+:  GNU  GPL  version  3  or
       later <https://gnu.org/licenses/gpl.html>.

       This  is  free  software:  you  are free to change and redistribute it.
       There is NO WARRANTY, to the extent permitted by law.

FSTR 0.1.1                        2025-04-06                           FSTR(1)

License

GNU General Public License v3.0

About

Substitute placeholders in strings.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published
0