Giter Site home page Giter Site logo

Comments (9)

fdncred avatar fdncred commented on May 20, 2024

This one was written in nu_script by @giggio #11470 (comment)
https://github.com/giggio/nuscripts/blob/main/scripts/history-command.nu

# Deletes a history entry.
def 'history delete' [
  id: int = 0 # the id of the history entry to delete
  --last # delete the last entry, ignore the id, if passed
  ] {
  if $last {
    open $nu.history-path | query db $"delete from history where id = \(select id from \(select id from history order by id desc LIMIT 2) order by id asc LIMIT 1)"
  } else {
    if $id == 0 {
      echo "You must pass an id or use --last"
      exit 1
    }
    open $nu.history-path | query db $"delete from history where id = ($id)"
  }
  null
}

from nushell.

Hofer-Julian avatar Hofer-Julian commented on May 20, 2024

Are you suggesting adding it to std, or did you just mention it for inspiration?

from nushell.

fdncred avatar fdncred commented on May 20, 2024

Are you suggesting adding it to std, or did you just mention it for inspiration?

Either? I've never really used it, but it looks sound. Is this how you'd want a history remove-item to work?

from nushell.

Hofer-Julian avatar Hofer-Julian commented on May 20, 2024

Is this how you'd want a history remove-item to work?

I think so?
To be honest I don't fully understand what this does:
\(select id from \(select id from history order by id desc LIMIT 2) order by id asc LIMIT 1)

I've assumed simply grabbing the entry with the correct id would be enough

from nushell.

fdncred avatar fdncred commented on May 20, 2024

ok.

ya, i'm not sure why the LIMIT 2 and then LIMIT 1. I try to stay away from nested queries. @gigggio i assume you're doing that for some specific reason that we aren't seeing. can you provide any insight?

from nushell.

giggio avatar giggio commented on May 20, 2024

Yes, there is a reason. That is for deleting the last command. But the command you just entered became the last, so what you actually need to do is delete the one before last. That is what that does. As the first query is limiting to 2 rows only, I didn't see a problem to nest. If there is a better way to get the row before the last one I'd like to know, I can update my version, too.

And now that I'm saying that I realize that maybe you'd want to delete the last from your current session, and I'm not doing that filtering. I think I'll update my script. :)

from nushell.

fdncred avatar fdncred commented on May 20, 2024

Please share your script if you decide to update it.

from nushell.

giggio avatar giggio commented on May 20, 2024

I just updated it:

https://github.com/giggio/nuscripts/blob/067c0479e876fd93825e793715bd5ddffcbefe4f/scripts/history-command.nu#L19-L34

from nushell.

fdncred avatar fdncred commented on May 20, 2024

nice! Thanks @giggio - just adding it here for fun. I understand why you do the query for --last now. Good work!

# Deletes a history entry.
def 'history delete' [
  id: int = 0 # the id of the history entry to delete
  --last # delete the last entry, ignore the id, if passed
  ] {
  if $last {
    open $nu.history-path | query db $"delete from history where id = \(select id from \(select id from history where session_id = (history session) order by id desc LIMIT 2) order by id asc LIMIT 1)"
  } else {
    if $id == 0 {
      echo "You must pass an id or use --last"
      exit 1
    }
    open $nu.history-path | query db $"delete from history where id = ($id)"
  }
  null
}

from nushell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.