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)
- start https://www.nushell.sh will open multiple instances HOT 3
- [Feature Request] umask functionality
- Behavior of `~` is inconsistent with user expectation HOT 3
- `help command` repeats help for any aliases
- mv breaks files if partially failed
- Command mode supports positional arguments HOT 2
- Allow `rename` to handle possibly-empty columns
- find command adds colors to result also in scripts
- "to json --raw" does not “remove all whitespace” as documented
- Command `debug info` reports incorrect mem usage HOT 4
- 0.90.1 regression: alt+d throws an error message HOT 15
- run-external is expanding globs (but shouldn't on Windows) with no way to opt out HOT 1
- Redirection: `e>|` and `e>` doesn't work properly if external command runs failed
- Ability to set HOME directory on windows (aka ~) HOT 1
- Autocompletion does not correctly handle Unicode characters.
- Auto-source config files in `$nu.default-config-dir/conf.d` and modules from `$nu.default-config-dir/modules.d` HOT 11
- nushell interprets any word containing 'date' in the command wrongly and provide date usage as output HOT 2
- Panic when completing with `..`
- Parsing a `register` command at the prompt can execute arbitrary files
- Python example is broken HOT 4
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.