Skip to content
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

Fix issues related to quoting #954

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions modules/cwdhist/mod.nu
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
def quote [...t] {
let s = $t | str join '' | str replace -a "'" "''"
$"'($s)'"
}

def __cwdhist_menu [] {
{
name: cwdhist_menu
Expand All @@ -14,12 +19,12 @@ def __cwdhist_menu [] {
}
source: { |buffer, position|
#$"[($position)]($buffer);(char newline)" | save -a ~/.cache/cwdhist.log
let t = ($buffer | split row ' ' | last)
let t = quote '%' ($buffer | split row ' ' | last) '%'
if $env.cwd_history_full {
open $nu.history-path | query db $"
select cwd as value, count\(*) as cnt
select cwd as value, count\(*\) as cnt
from history
where cwd like '%($t)%'
where cwd like ($t)
group by cwd
order by cnt desc
limit 50
Expand All @@ -28,7 +33,7 @@ def __cwdhist_menu [] {
open $env.cwd_history_file | query db $"
select cwd as value, count
from cwd_history
where cwd like '%($t)%'
where cwd like ($t)
order by count desc
limit 50
;"
Expand Down Expand Up @@ -69,12 +74,12 @@ export def empty-sqlite [] {

export def 'cwd history delete' [cwd] {
open $env.cwd_history_file
| query db $"delete from cwd_history where cwd = '($cwd)';"
| query db $"delete from cwd_history where cwd = (quote $cwd);"
}

export-env {
$env.cwd_history_full = false
$env.cwd_history_file = '~/.cache/nu_cwd_history.sqlite'
$env.cwd_history_file = ([$nu.data-dir 'cache'] | path join 'nu_cwd_history.sqlite')

if not ($env.cwd_history_file | path exists) {
empty-sqlite | save -f $env.cwd_history_file
Expand All @@ -95,9 +100,9 @@ export-env {
}
open $env.cwd_history_file
| query db $"
insert into cwd_history\(cwd)
values \('($path)')
on conflict\(cwd)
insert into cwd_history\(cwd\)
values \((quote $path)\)
on conflict\(cwd\)
do update set
count = count + 1,
recent = datetime\('now', 'localtime');"
Expand Down
Loading