Comments (9)
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.
Are you suggesting adding it to std, or did you just mention it for inspiration?
from nushell.
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.
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.
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.
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.
Please share your script if you decide to update it.
from nushell.
I just updated it:
from nushell.
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)
- newlines near `and` causes conditionals to be treated like commands HOT 2
- [how-do] make html docs pages based on custom functions HOT 1
- Add a `tree` viewer to display hierarchies in tree format HOT 1
- Metadata lost inside closures with `$in` HOT 2
- Lua doesn't read environment variables correctly HOT 5
- Rounding Issues in `format duration` HOT 3
- `tee` doesn't work within a loop HOT 5
- `polars filter-with $mask` won't work HOT 6
- Windows: can get stuck with bad PWD when `cd`ing to drive root HOT 5
- Show error message when processes are killed by SIGSEGV/SIGILL/etc HOT 3
- 'cargo install nushell' can't find nushell in registry 'cargo-io' HOT 3
- 'ls' in nu hangs with 100% CPU on a directory with ~4000 files (doesn't finish in 5+ minutes) HOT 2
- nu promps always has the letter 'q' at the end of the prompt HOT 3
- Completion for overlay use
- Input/Output types of nu script execution help message output are always any HOT 2
- Attention: Nightly build of release binaries failed
- Child processes can inherit initial environment variables after `hide-env` HOT 1
- ls doesn't work inside folders with some characters in the name HOT 6
- ENV_CONVERSIONS is not applied when setting env HOT 2
- parse -r capture group naming inconsistency with standard regex. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nushell.