Skip to content

Commit d70af4e

Browse files
committed
Fix issues related to quoting
1 parent d04eea6 commit d70af4e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

modules/cwdhist/mod.nu

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
def quote [...t] {
2+
let s = $t | str join '' | str replace -a "'" "''"
3+
$"'($s)'"
4+
}
5+
16
def __cwdhist_menu [] {
27
{
38
name: cwdhist_menu
@@ -14,12 +19,12 @@ def __cwdhist_menu [] {
1419
}
1520
source: { |buffer, position|
1621
#$"[($position)]($buffer);(char newline)" | save -a ~/.cache/cwdhist.log
17-
let t = ($buffer | split row ' ' | last)
22+
let t = quote '%' ($buffer | split row ' ' | last) '%'
1823
if $env.cwd_history_full {
1924
open $nu.history-path | query db $"
20-
select cwd as value, count\(*) as cnt
25+
select cwd as value, count\(*\) as cnt
2126
from history
22-
where cwd like '%($t)%'
27+
where cwd like ($t)
2328
group by cwd
2429
order by cnt desc
2530
limit 50
@@ -28,7 +33,7 @@ def __cwdhist_menu [] {
2833
open $env.cwd_history_file | query db $"
2934
select cwd as value, count
3035
from cwd_history
31-
where cwd like '%($t)%'
36+
where cwd like ($t)
3237
order by count desc
3338
limit 50
3439
;"
@@ -69,12 +74,12 @@ export def empty-sqlite [] {
6974

7075
export def 'cwd history delete' [cwd] {
7176
open $env.cwd_history_file
72-
| query db $"delete from cwd_history where cwd = '($cwd)';"
77+
| query db $"delete from cwd_history where cwd = (quote $cwd);"
7378
}
7479

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

7984
if not ($env.cwd_history_file | path exists) {
8085
empty-sqlite | save -f $env.cwd_history_file
@@ -95,9 +100,9 @@ export-env {
95100
}
96101
open $env.cwd_history_file
97102
| query db $"
98-
insert into cwd_history\(cwd)
99-
values \('($path)')
100-
on conflict\(cwd)
103+
insert into cwd_history\(cwd\)
104+
values \((quote $path)\)
105+
on conflict\(cwd\)
101106
do update set
102107
count = count + 1,
103108
recent = datetime\('now', 'localtime');"

0 commit comments

Comments
 (0)