jazzband / Watson

:watch: A wonderful CLI to track your time!
http://tailordev.github.io/Watson/
MIT License
2.44k stars 239 forks source link

Possibility to remove the project #192

Open ladisone opened 6 years ago

ladisone commented 6 years ago

It would be good to delete the entire project.

jmaupetit commented 6 years ago

Hi @ladisone! You would like to remove a project and all related frames?

ladisone commented 6 years ago

@jmaupetit Yes and all related frames.

montrealks commented 6 years ago

+1

jnsebgosselin commented 6 years ago

I'll like to see this feature also. I can try to submit a PR to address this.

NateV commented 6 years ago

Alternatively, or additionally - what about the ability to mark a project as "complete", so that it doesn't show up in the list of projects with watson projects?

3ynm commented 5 years ago

while you wait for the PR you can use this (add to your .bashrc or .zshrc):

# watson_rm_all <project|tag> <project_or_tag_name>
watson_rm_all () { watson log --$1 $2 | sed -n -E -e 's/^\s+([a-z0-9]+)\s.*/\1/p' | while read id; do watson remove -f "$id"; done }
jmaupetit commented 5 years ago

Nice snippet, thanks!

xilopaint commented 5 years ago

while you wait for the PR you can use this (add to your .bashrc or .zshrc):

# watson_rm_all <project|tag> <project_or_tag_name>
watson_rm_all () { watson log --$1 $2 | sed -n -E -e 's/^\s+([a-z0-9]+)\s.*/\1/p' | while read id; do watson remove -f "$id"; done }

@hacktivista does this snippet still work for you? It doesn't work for me.

3ynm commented 5 years ago

it does for me, probably you want to delete items no longer listed by default? (1 month ago)

xilopaint commented 5 years ago

@hacktivista maybe I'm doing something wrong? Look:

$ watson start apollo11 +reactor +module
Starting project apollo11 [reactor, module] at 21:52
$ watson stop
Stopping project apollo11 [reactor, module], started just now. (id: 6c68152)
$ watson_rm_all project apollo11
$ watson frames
6c68152

As you can see the frame is still there after running watson_rm_all. Am I missing anything?

3ynm commented 5 years ago

I've just tested it out with your example and it's working for me... Maybe it has something to do with your environment? I'm thinking it has to do with the sed implementation. I'm using GNU sed 4.7.

xilopaint commented 5 years ago

I've just tested it out with your example and it's working for me... Maybe it has something to do with your environment? I'm thinking it has to do with the sed implementation. I'm using GNU sed 4.7.

That was the problem. The macOS sed version is not GNU sed. I've installed GNU sed and now it seems to work but not with projects that have spaces in the name. Is this an issue of your implementation?

3ynm commented 5 years ago

Yes

owenh000 commented 1 year ago

Thanks, @hacktivista, for the shell snippet.

For anyone else looking for a way to delete old projects/tags, I suggest revising this as follows:

# watson_rm_all <project|tag> <project_or_tag_name>
watson_rm_all () { watson log --all --$1 "$2" | sed -n -E -e 's/^\s+([a-z0-9]+)\s.*/\1/p' | while read id; do watson remove -f "$id"; done }
NotJoeMartinez commented 7 months ago

This is my python solution

Make this script in a dedicated folder for me it's ~/.local/scripts/watson_rm/watson_rm.py.

import subprocess
import json
import sys

def main():
    project_name = sys.argv[1]

    confirm = input(f"Confirming deletion of project: {project_name} (y/n): ")   

    if confirm.capitalize() != 'Y':
        print("Exiting...")
        sys.exit(0)

    command = [
        'watson',
        'log', 
        '--project',
        '--all',
        project_name,
        '--no-pager',
        '--json'
    ]

    command_str = ' '.join(command)
    watson_output = subprocess.run(command_str, 
                                   stdout=subprocess.PIPE, 
                                   text=True,
                                   shell=True)

    output = json.loads(watson_output.stdout)
    frames = [elem['id'] for elem in output]

    for frame in frames:
        subprocess.run(f'watson remove {frame} --force', shell=True)

if __name__ == '__main__':
    main()

Then put this in you're bash or zsh alias file:

alias watson_rm="python3 ~/.local/scripts/watson_rm/watson_rm.py"

Edit: Added --all flag to remove all records

ezbik commented 1 week ago

@NotJoeMartinez thanks! Please make an edit:

     '--no-pager',
+    '--all',
     '--json'

so it handles all records , not just those of 7 last days .