ltackett / musictocodeto

MTCT is a CLI-like interface for SoundCloud written in React.

Home Page:http://musictocodeto.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

As a user, I should be able to browse resources by issuing the `cd` command

ltackett opened this issue · comments

This will work pretty much exactly like *nix.

cd will manage a path array in localStorage. Some programs (such as ls) will be path-aware.

Jotted down from my notes

# cd - sets `path`
# =============================================================================
cd: (newPath) ->
  if localStorage.path
    path = JSON.parse(localStorage.path)
  else
    path = []

  # Going back one or multiple dirs
  if newPath.indexOf('..') > -1
    newPath.split('/').map (p) ->
      if p == '..' then path.pop()

  # Add new path to path array.
  # We will need to do error checking on this
  # to make sure the value of newPath exists.
  else
    path.push newPath

  # Apply to localStorage
  localStorage.setItem('path', newPath)