A Fortune clone using Go!
-
fortune
sudo apt-get install fortune
Compile the code into an executable.
go build -o gofortune
You can discover the install path by running the go list command, as in the following example:
go list -f '{{.Target}}'
Add the Go install directory to your system's shell path.
As an alternative, you can change the install target by setting the GOBIN variable using the go env command:
go env -w GOBIN=/path/to/your/bin
Compile and install the package.
go install github.com/dimanyfantakis/gofortune
Run the application
gofortune
Or add gofortune
to your ~/.bashrc
file.
If you don't want to get a fortune on every new terminal session but rather once per login then you can do the following.
In the ~/.bashrc
file add the following.
# Define the flag file path
flag_file="/tmp/.firstrun_$USER"
# If the flag file doesn't exist
if [ ! -f "$flag_file" ]; then
# Execute the gofortune command
gofortune
# Create the flag file in /tmp
touch "$flag_file"
fi
In the ~/.bash_logout
file add the following.
flag_file="/tmp/.firstrun_$USER"
if [ -f "$flag_file" ]; then
rm -f "$flag_file"
fi