Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ jobs:
elif [ "${{ matrix.shell }}" = "fish" ]; then
fish -c "source ~/.config/fish/config.fish && echo 'Fish configuration loaded'"
fi
ls ~/.malamtime
ls ~/.malamtime/bin
ls ~/.shelltime
ls ~/.shelltime/bin
14 changes: 7 additions & 7 deletions hooks/fish.fish
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env fish

# Check if malamtime CLI exists
if not command -v malamtime &> /dev/null
echo "Warning: malamtime CLI not found. Please install it to enable time tracking."
# Check if shelltime CLI exists
if not command -v shelltime &> /dev/null
echo "Warning: shelltime CLI not found. Please install it to enable time tracking."
else
malamtime gc
shelltime gc
end

# Create a timestamp for the session when the shell starts
set -g MALAM_SESSION_ID (date +%Y%m%d%H%M%S)
set -g SESSION_ID (date +%Y%m%d%H%M%S)

# Define the preexec function
function fish_preexec --on-event fish_preexec
if string match -q 'exit*' -- $argv; or string match -q 'logout*' -- $argv; or string match -q 'reboot*' -- $argv
return
end

malamtime track -s=fish -id=$MALAM_SESSION_ID -cmd="$argv" -p=pre &
shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=pre &
end

# Define the postexec function
Expand All @@ -26,5 +26,5 @@ function fish_postexec --on-event fish_postexec
return
end
# This event is triggered before each prompt, which is after each command
malamtime track -s=fish -id=$MALAM_SESSION_ID -cmd="$argv" -p=post -r=$LAST_RESULT &
shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=post -r=$LAST_RESULT &
end
14 changes: 7 additions & 7 deletions hooks/zsh.zsh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env zsh

# Check if malamtime command exists
if ! command -v malamtime &> /dev/null
# Check if shelltime command exists
if ! command -v shelltime &> /dev/null
then
echo "Warning: malamtime command not found. Please install it to track shell usage."
echo "Warning: shelltime command not found. Please install it to track shell usage."
else
malamtime gc
shelltime gc
fi

# Create a timestamp for the session when the shell starts
MALAM_SESSION_ID=$(date +%Y%m%d%H%M%S)
SESSION_ID=$(date +%Y%m%d%H%M%S)

# Define the preexec function
preexec() {
Expand All @@ -18,7 +18,7 @@ preexec() {
return
fi

malamtime track -s=zsh -id=$MALAM_SESSION_ID -cmd=$argv -p=pre &
shelltime track -s=zsh -id=$SESSION_ID -cmd=$argv -p=pre &
}

# Define the postexec function (in zsh, it's called precmd)
Expand All @@ -28,5 +28,5 @@ precmd() {
if [[ $argv =~ ^(exit|logout|reboot) ]]; then
return
fi
malamtime track -s=zsh -id=$MALAM_SESSION_ID -cmd=$argv -p=post -r=$LAST_RESULT &
shelltime track -s=zsh -id=$SESSION_ID -cmd=$argv -p=post -r=$LAST_RESULT &
}
50 changes: 25 additions & 25 deletions install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -87,73 +87,73 @@ else
exit 1
fi

# Check if the malamtime file exists
if [ ! -f "malamtime" ]; then
echo "Error: malamtime binary not found after extraction"
# Check if the shelltime file exists
if [ ! -f "shelltime" ]; then
echo "Error: shelltime binary not found after extraction"
exit 1
fi

# Check if $HOME/.malamtime/bin exists, create if not
if [ ! -d "$HOME/.malamtime/bin" ]; then
echo "Creating $HOME/.malamtime/bin directory..."
mkdir -p "$HOME/.malamtime/bin"
# Check if $HOME/.shelltime/bin exists, create if not
if [ ! -d "$HOME/.shelltime/bin" ]; then
echo "Creating $HOME/.shelltime/bin directory..."
mkdir -p "$HOME/.shelltime/bin"
if [ $? -eq 0 ]; then
echo "Directory created successfully."
else
echo "Failed to create directory. Please check your permissions."
exit 1
fi
else
echo "$HOME/.malamtime/bin directory already exists."
echo "$HOME/.shelltime/bin directory already exists."
fi

# Move the binary to the appropriate location
if [[ "$OS" == "Darwin" ]] || [[ "$OS" == "Linux" ]]; then
mv malamtime "$HOME/.malamtime/bin/"
mv shelltime "$HOME/.shelltime/bin/"
# elif [[ "$OS" == "MINGW64_NT" ]] || [[ "$OS" == "MSYS_NT" ]] || [[ "$OS" == "CYGWIN_NT" ]]; then
# mv malamtime /c/Windows/System32/
# mv shelltime /c/Windows/System32/
fi

# Add $HOME/.malamtime/bin to user path
# Add $HOME/.shelltime/bin to user path
if [[ "$OS" == "Darwin" ]] || [[ "$OS" == "Linux" ]]; then
# For Zsh
if ! grep -q '$HOME/.malamtime/bin' "$HOME/.zshrc"; then
echo 'export PATH="$HOME/.malamtime/bin:$PATH"' >> "$HOME/.zshrc"
echo "Updated .zshrc to include $HOME/.malamtime/bin in PATH"
if ! grep -q '$HOME/.shelltime/bin' "$HOME/.zshrc"; then
echo 'export PATH="$HOME/.shelltime/bin:$PATH"' >> "$HOME/.zshrc"
echo "Updated .zshrc to include $HOME/.shelltime/bin in PATH"
fi

# For Fish
if ! grep -q '$HOME/.malamtime/bin' "$HOME/.config/fish/config.fish"; then
echo 'set -gx PATH $HOME/.malamtime/bin $PATH' >> "$HOME/.config/fish/config.fish"
echo "Updated config.fish to include $HOME/.malamtime/bin in PATH"
if ! grep -q '$HOME/.shelltime/bin' "$HOME/.config/fish/config.fish"; then
echo 'set -gx PATH $HOME/.shelltime/bin $PATH' >> "$HOME/.config/fish/config.fish"
echo "Updated config.fish to include $HOME/.shelltime/bin in PATH"
fi

echo "Please restart your shell or run 'source ~/.zshrc' (for Zsh) or 'source ~/.config/fish/config.fish' (for Fish) to apply the changes."
fi

# Clean up
rm -f "$FILENAME"
# rm -rf malamtime
# rm -rf shelltime


# HELP WANTED
# I don't know where the `/bin` folder in windows. so i don't know where should the binaries be installed.
# if you know, please let me know.

# Success message
echo "Installation successful! You can try the command by running 'malamtime -h'."
echo "Installation successful! You can try the command by running 'shelltime -h'."

if [[ "$OS" == "MINGW64_NT" ]] || [[ "$OS" == "MSYS_NT" ]] || [[ "$OS" == "CYGWIN_NT" ]]; then
echo "Please note that the binaries are not installed yet. please move `/tmp/malamtime` to your `/bin/` folder manually."
echo "btw if you know where should the binaries be installed, please raise an issue or pull request. (https://github.com/malamtime/cli)."
echo "Please note that the binaries are not installed yet. please move `/tmp/shelltime` to your `/bin/` folder manually."
echo "btw if you know where should the binaries be installed, please raise an issue or pull request. (https://github.com/shelltime/cli)."
fi


# STEP 2
# insert a preexec and postexec script to user configuration, including `zsh` and `fish`

# Define the path
hooks_path="$HOME/.malamtime/hooks"
hooks_path="$HOME/.shelltime/hooks"

# Check if the directory exists
if [ ! -d "$hooks_path" ]; then
Expand Down Expand Up @@ -236,11 +236,11 @@ echo "\n"

# Final message
echo "To complete the setup, please follow these steps:"
echo "1. Visit https://malamtime.com to obtain an open token."
echo "1. Visit https://shelltime.xyz to obtain an open token."
echo "2. Run the following command in your terminal:"
echo " malamtime init --token=TOKEN"
echo " shelltime init --token=TOKEN"
echo " (Replace TOKEN with the actual token you received)"
echo "3. Source your shell configuration file:"
echo " For Zsh users: source ~/.zshrc"
echo " For Fish users: source ~/.config/fish/config.fish"
echo "Only after completing these steps will malamtime be fully functional."
echo "Only after completing these steps will shelltime be fully functional."