Skip to content

Commit 296584a

Browse files
committed
fixes #763
1 parent 1e1b611 commit 296584a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

fastcore/tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def run_cmd(
5757
try:
5858
ensure(not (disallow_re and re.search(disallow_re, argstr)), 'args disallowed')
5959
ensure(not (allow_re and re.search( allow_re, argstr)), 'args not allowed')
60-
outp = run([cmd] + split(argstr), text=True, stdin=DEVNULL, capture_output=True)
60+
args = [str(Path(a).expanduser()) if a.startswith('~') else a for a in split(argstr)]
61+
outp = run([cmd] + args, text=True, stdin=DEVNULL, capture_output=True)
6162
except: return explain_exc(f'running cmd')
6263
res = outp.stdout
6364
if res and outp.stderr: res += '\n'

nbs/12_tools.ipynb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@
228228
" try:\n",
229229
" ensure(not (disallow_re and re.search(disallow_re, argstr)), 'args disallowed')\n",
230230
" ensure(not (allow_re and re.search( allow_re, argstr)), 'args not allowed')\n",
231-
" outp = run([cmd] + split(argstr), text=True, stdin=DEVNULL, capture_output=True)\n",
231+
" args = [str(Path(a).expanduser()) if a.startswith('~') else a for a in split(argstr)]\n",
232+
" outp = run([cmd] + args, text=True, stdin=DEVNULL, capture_output=True)\n",
232233
" except: return explain_exc(f'running cmd')\n",
233234
" res = outp.stdout\n",
234235
" if res and outp.stderr: res += '\\n'\n",
@@ -253,27 +254,27 @@
253254
"name": "stdout",
254255
"output_type": "stream",
255256
"text": [
256-
"\u001b[34m__pycache__\u001b[m\u001b[m\n",
257-
"_parallel_win.ipynb\n",
258-
"_quarto.yml\n",
259-
"00_test.ipynb\n",
260-
"000_tour.ipynb\n",
261-
"01_basics.ipynb\n",
262-
"02_foundation.ipynb\n",
263-
"03_xtras\n"
257+
"\u001b[34maai-ws\u001b[m\u001b[m\n",
258+
"\u001b[34mApplications\u001b[m\u001b[m\n",
259+
"autoexec.ipynb\n",
260+
"\u001b[34mbooks\u001b[m\u001b[m\n",
261+
"cachy.jsonl\n",
262+
"\u001b[34mchats\u001b[m\u001b[m\n",
263+
"CRAFT.ipynb\n",
264+
"\u001b[34mDesktop\u001b\n"
264265
]
265266
}
266267
],
267268
"source": [
268-
"print(run_cmd('ls')[:128])"
269+
"print(run_cmd('ls', '~')[:128])"
269270
]
270271
},
271272
{
272273
"cell_type": "markdown",
273274
"id": "ee40009c",
274275
"metadata": {},
275276
"source": [
276-
"Note that, for tool safety, this is not passed through the shell, so wildcards, env vars, etc will not work:"
277+
"Note that, for tool safety, this is not passed through the shell, so wildcards, env vars, etc will not work (although `~` will):"
277278
]
278279
},
279280
{

0 commit comments

Comments
 (0)