« get me outta code hell

Expand ~ in local crawl - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-07-03 01:15:28 -0300
committerFlorrie <towerofnix@gmail.com>2018-07-03 01:15:28 -0300
commit35d24ba00a4885ac086c61412ea6e084a0fa0afa (patch)
tree7838eae8194f3f5fd1bb088001f2107c110325a2
parent1ec8d7987879d8717dc251cbbdbd419622c5b6e2 (diff)
Expand ~ in local crawl
-rw-r--r--crawlers.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/crawlers.js b/crawlers.js
index 5a4987a..1db02fd 100644
--- a/crawlers.js
+++ b/crawlers.js
@@ -1,6 +1,7 @@
 const fs = require('fs')
 const path = require('path')
 const naturalSort = require('node-natural-sort')
+const expandHomeDir = require('expand-home-dir')
 const fetch = require('node-fetch')
 const url = require('url')
 const { downloadPlaylistFromOptionValue, promisifyProcess } = require('./general-util')
@@ -238,8 +239,9 @@ function crawlLocal(dirPath, extensions = [
       dirPath = decodeURIComponent(url.pathname)
     }
   } catch (error) {
-    // If it's not a URL, don't do anything special - it's (assumedly) an
-    // ordinary path ("/path/to/the directory").
+    // If it's not a URL, it's (assumedly) an ordinary path ("/path/to/the directory").
+    // In this case we'll expand any ~ in the path (e.g. ~/Music -> /home/.../Music).
+    dirPath = expandHomeDir(dirPath)
   }
 
   return readDir(dirPath).then(items => {