Truthtable update: now installed into bin instead of an alias

This commit is contained in:
TiagoRG 2023-02-20 22:21:57 +00:00
parent d167f7bb9a
commit 0da1e9b841
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
4 changed files with 40 additions and 55 deletions

View File

@ -1,15 +1,17 @@
# Truth Table Builder # Truth Table Builder
### Script to build the truth table for a given function. ### Script to build the truth table for a given function.
--- ---
## Installing ## Installing
#### 1. Head over to [Release](https://github.com/TiagoRG/uaveiro-leci/releases/tag/ttb) and download the python file. #### 1. Head over to [Release](https://github.com/TiagoRG/uaveiro-leci/releases/tag/ttb) and download the zip folder.
#### 2. Save it on any directory and then open the directory. #### 2. Extract it into any location and then open that location.
#### 3. Inside the directory, right click and choose "Open in terminal" #### 3. Inside the directory, right click and choose "Open in terminal"
![- Unable to load image -](https://github.com/TiagoRG/uaveiro-leci/blob/master/tools/truthtable/openInTerminal.png) ![- Unable to load image -](https://github.com/TiagoRG/uaveiro-leci/blob/master/tools/truthtable/openInTerminal.png)
#### 4. Run the following command: #### 4. Run the following commands:
`python3 truthtable.py bash` 1. Make sure the setup.sh is executable: `sudo chmod +x setup.sh`<br>
#### 5. Relaunch the terminal and you will have the `truthtable` command 2. Install the script: `./setup.sh install`
#### 5. Done! You can now use the tool by running `truthtable` in terminal.
--- ---
#### Use `truthtable usage` to know better how to use this tool. #### Use `truthtable usage` to know better how to use this tool.
#### If you want to change the location of the `truthtable.py` file, move it to another directory, open that directory in terminal and run #### If you want to remove the tool, run `./setup.sh uninstall`, delete setup.sh and it will be removed.
`python3 truthtable.py bash --reset`

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 0 B

18
tools/truthtable/setup.sh Executable file
View File

@ -0,0 +1,18 @@
if [ "$1" = "install" ]; then
echo "Installing truthtable..."
sudo mv truthtable.py /usr/bin/
sudo touch /usr/bin/truthtable
sudo chmod o+w /usr/bin/truthtable
echo "python3 /usr/bin/truthtable.py \"\$1\"" > /usr/bin/truthtable
sudo chmod o-w /usr/bin/truthtable
sudo chmod +x /usr/bin/truthtable
echo "Done. You can now delete this file or keep it to uninstall truthtable."
echo "You can now run truthtable by typing 'truthtable' in the terminal."
elif [ "$1" = "uninstall" ]; then
echo "Uninstalling truthtable..."
sudo rm /usr/bin/truthtable.py
sudo rm /usr/bin/truthtable
echo "Done."
else
echo "Usage: ./setup.sh [install|uninstall]"
fi

View File

@ -14,45 +14,10 @@ truthtable '<function>':
> Variables: a-z > Variables: a-z
> Operators: +, *, ~, (, ); You can't use ~ before () > Operators: +, *, ~, (, ); You can't use ~ before ()
truthtable bash:
Adds the command truthtable to bash, so you can use it from anywhere.
truthtable bash --reset:
Resets the command truthtable in bash in case it's broken, so you can use it from anywhere.
truthtable usage: truthtable usage:
Prints this message.""") Prints this message.""")
return return
if sys.argv[1] == "bash":
username = os.getlogin()
if len(sys.argv) == 2:
with open(f'/home/{username}/.bashrc', 'r') as bashrc:
for line in bashrc:
if line.startswith('alias truthtable='):
print('Command already exists, try using, after opening a new terminal, truthtable \'<function>\'')
return
os.system(f'echo "\n\nalias truthtable=\'python3 {pathlib.Path(__file__).parent.absolute()}/truthtable.py\'\n" >> \'/home/{username}/.bashrc\'')
print('Command added to bash, try using truthtable <function>.\nIf it doesn\'t work, do truthtable bash --reset.')
elif sys.argv[2] == '--reset':
with open(f'/home/{username}/.bashrc', 'r') as bashrc:
lines = bashrc.readlines()
linesDict = {}
index = 1
for line in lines:
linesDict[index] = line
index += 1
for key in linesDict:
if linesDict[key].startswith('alias truthtable='):
del linesDict[key]
break
string = ''
for key in linesDict:
string += linesDict[key]
string += f'\n\nalias truthtable=\'python3 {pathlib.Path(__file__).parent.absolute()}/truthtable.py\'\n'
with open(f'/home/{username}/.bashrc', 'w') as bashrc:
bashrc.write(string)
print('Command readded to bash, try using, after opening a new terminal, truthtable <function>.')
else:
function = sys.argv[1] function = sys.argv[1]
validVariables = r"[a-z]" validVariables = r"[a-z]"