Skip to content

Allows you to toggle the value of a variable in a file

License

Notifications You must be signed in to change notification settings

happycod3r/zsh-toggles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zsh Toggles v1.1.0


Zsh-Toggle is a function that will allow you to toggle the value of a variable in a file. If you want to let a user turn an option on or off in your program you can do it easily with Zsh-Toggle.

Example


To download and install zsh-toggles follow choose an install method and follow the corresponding steps. Once fininshed jump to the Usage section.

  1. Download and place the zsh-toggles folder in a location of your choosing.
  2. Next source the script as shown in the Usage section.
  1. Open your terminal and navigate to the directory where you want to clone the repository:
cd where/I/want/to/install
  1. Next run the following command to clone the repository to the chosen location:
git clone https://github.com/happycod3r/zsh-toggles.git
  1. Pick a directory to download it to:
cd where/I/want/
  1. Paste the following line into your terminal and press the Enter (^M) key:
curl https://github.com/happycod3r/zsh-toggles.git

Parmeters for zsh-toggle()

  • arg1: EXPORT
    • [true|false]
    • Whether the variable has an export statement or not. Default is 'false'
  • arg2: DQUOTES
    • [true|false|none]
    • Whether the variable has double quotes, single quotes or none. Default is 'true'
  • arg3: VAR_NAME
    • [string]
    • The name of the variable
  • arg4: VALUE
    • [string]
    • The current value of the variable
  • arg5: ALT_VALUE
    • [string]
    • The alternte value for the variable
  • arg6: FILE_PATH
    • [string]
    • The fully qualified path to the file containing the variable

In the file that contains the variable(s) that you want to toggle. The variable should ...

  • be on a line of its own.
  • be only one of the following formats:
    • $MY_VAR="true" no export statement, double quotes
    • $MY_VAR='true' no export statement, single quotes.
    • $MY_VAR=true no export statement, no quotes.
    • export $MY_VAR="true" export statement, double quotes
    • export $MY_VAR='false' export statement, single quotes.
    • export $MY_VAR=false export statement, no quotes.
  • be initialized with a value such as true|false, on|off, 1|0, yes|no John|Amy etc.
  • It can be any two values that you want to toggle between.

The variable you are toggling should be initialized in its file already with either VALUE or ALT_VALUE otherwise it won't work. For example if you set

VALUE="yes"
ALT_VALUE="no" 

then in the file @ FILE_PATH the variable should be initialized with either "yes" or "no". ex. MY_VAR="yes" or MY_VAR="no" The same with the other options too. If you set DQUOTES or EXPORT to "true" then the variable value should be wrapped in double quotes and/or be exported already in the file. Your basically describing the variable with these options

Another example:

If you call zsh-toggle like this

zsh-toggle false true TEST "false" "true" "$(pwd)/test.conf"

then the variable in the file your pointing at with the last argument should look like this:

TEST="false"
# or
TEST="true"

If you call zsh-toggle like this

zsh-toggle true false TEST "on" "off" "$(pwd)/test.conf"

then the variable in the file your pointing at with the last argument should look like this:

export TEST='on'
# or
export TEST='off'

You can also call zsh-toggle passing "none" for the 2nd argument to use no quotes like this:

zsh-toggle false none TEST "false" "true" "$(pwd)/test.conf"

In this case the variable in the file your pointing at with the last argument should look like this:

TEST=false
# or
TEST=true

If you have any feature requests, suggestions or general questions you can reach me via any of the methods listed below in the Contacts section.


Reporting a vulnerability or bug?

Do not submit an issue or pull request: A general rule of thumb is to never publicly report bugs or vulnerabilities because you might inadvertently reveal it to unethical people who may use it for bad. Instead, you can email me directly at: paulmccarthy676@gmail.com. I will deal with the issue privately and submit a patch as soon as possible.


Author: Paul M.


Releases

No releases published

Packages

No packages published

Languages