-
Notifications
You must be signed in to change notification settings - Fork 315
Fix invalid code in history utils #1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,40 +24,41 @@ def flatten_fields [args] { | |
| def sql [q] { | ||
| [ | ||
| [$q.select ['select', ' as ', ', ']] | ||
| [$q.from ['from', ' as ', ' join ']] | ||
| [[$q.from] ['from', ' as ', ' join ']] | ||
| [$q.where? ['where', ' ', ' and ']] | ||
| [$q.whereOr? ['or', ' ', ' or ']] | ||
| [$q.groupBy? ['group by', null, ', ']] | ||
| [$q.orderBy? ['order by', ' ', ', ']] | ||
| [$q.limit? ['limit', null, ' offset ']] | ||
| [[$q.limit?] ['limit', null, ' offset ']] | ||
| ] | ||
| | each {|x| $x.0 | flatten_fields $x.1 } | ||
| | flatten | ||
| | str join ' ' | ||
| } | ||
|
|
||
| # Displays the recent command history | ||
| export def 'history timing' [ | ||
| pattern? | ||
| --exclude(-x): string | ||
| --num(-n)=10 | ||
| --all(-a) | ||
| pattern?: string # Show commands matching the pattern | ||
| --exclude(-x): string # Exclude commands mathing the pattern | ||
| --num(-n)=10 # Maximum number or results | ||
| --all(-a) # Show commands for all directories (default: cwd) | ||
| ] { | ||
| open $nu.history-path | query db (sql { | ||
| from: history | ||
| where: [ | ||
| "cmd not like 'history timing%'" | ||
| (if ($pattern | is-not-empty) {[cmd like (quote '%' $pattern '%')]}) | ||
| (if ($exclude | is-not-empty) {[cmd not like (quote '%' $exclude '%')]}) | ||
| (if not $all {[cwd = (quote $env.PWD)]}) | ||
| ] | ||
| orderBy: [[start desc]] | ||
| select: [ | ||
| [duration_ms duration] | ||
| [command_line cmd] | ||
| [start_timestamp start] | ||
| (if $all {[$"replace\(cwd, '($env.HOME)', '~')" cwd]}) | ||
| [exit_status exit] | ||
| ] | ||
| where: [ | ||
| "cmd not like 'history timing%'" | ||
| (if ($pattern | is-not-empty) {[cmd like (quote '%' $pattern '%')]}) | ||
| (if ($exclude | is-not-empty) {[cmd not like (quote '%' $exclude '%')]}) | ||
| (if not $all {[cwd = (quote $env.PWD)]}) | ||
| ] | ||
| orderBy: [[start desc]] | ||
| limit: $num | ||
| }) | ||
| | update duration {|x| $x.duration | default 0 | do { $in * 1_000_000 } | into duration } | ||
|
|
@@ -66,8 +67,8 @@ export def 'history timing' [ | |
|
|
||
| def "nu-complete history dir" [] { | ||
| open $nu.history-path | query db (sql { | ||
| select: [cwd ['count(1)' count]] | ||
| from: history | ||
| select: [cwd ['count(1)' count]] | ||
| groupBy: [cwd] | ||
| orderBy: ['count desc'] | ||
| limit: 20 | ||
|
|
@@ -80,7 +81,7 @@ export def 'history top' [ | |
| num=10 | ||
| --before (-b): duration | ||
| --dir (-d) | ||
| --path(-p): list<string@"nu-complete history dir"> | ||
| --path(-p): list<directory> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this changed from 'nu-complete history dir'? it probably shouldn't be a type but it looks like it's intended to provid completions with --path
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see a syntax error for this. I'm guessing this isn't supported. I couldn't find a way to support autocomplete for lists. I could think of two alternatives:
|
||
| ] { | ||
| open $nu.history-path | query db (sql { | ||
| from: history | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No code change here. Just moved it down for a consistent order (from > select > where > groupBy > orderBy > limit).