*! v0.8.6 2018-08-10 delele not rename
* v0.8.5 2018-08-07 try to add path for search
* v0.8.4 2018-07-13 clean up syntax add path
* v0.8.3 2018-06-28 no , with options

// list cdproject commands in PERSONAL directory

capture program drop listcd
program define listcd
    version 13.0
    syntax [ anything ], [ DETails DIRectories PATHs NODELete]
    if "`paths'"!="" local directories directories // synonym for directories

//  setup for cd*.ado search

    local filespec "*"
    if "`anything'"!="" local filespec "`anything'"

    local cdsavefiles : dir "`c(sysdir_personal)'" files "cd`filespec'.ado"
    local currentpwd `"`c(pwd)'"'

//  get max length of cd* command names to line up output

    local cmdwidth = 0
    foreach file in `cdsavefiles' {
        local filelen = strlen("`file'")
        if `filelen'>`cmdwidth' local cmdwidth = `filelen'
    }
    local cmdwidth = `cmdwidth' - 3 // for .ado

//  loop through cd* commands

    foreach file in `cdsavefiles' {

        local cmd : subinstr local file ".ado" "", all

        * run quiety to determine if working directory exsits
        capture program drop `cmd'
        capture quietly `cmd'
        local wdmissing = 0
        if _rc!=0 local wdmissing = 1 // can't change to wd

        * list details
        if "`details'"=="details" {
            di `"{stata `cmd':`cmd'}"'
            _list_s_cd_globals
            di
            if `wdmissing' di as error _col(15) "working directory not found"
        }
        * list note or path
        else {
            local note `"$S_cdnote"'
            if ("`note'"=="" | "`directories'"=="directories") ///
                local note `"$S_cdwd"'
            local nspaces = `cmdwidth' - strlen("`cmd'")
            di `"{space `nspaces'}{stata `cmd':`cmd'} "' ///
                as text `" `note'"' _continue
            if "`nodelete'"=="nodelete" { // rename ado file to *.hold
                di `" ({stata dropcd `cmd',hold:drop})"' _continue
            }
            else {
                di `" - {stata dropcd `cmd':drop}"' _continue
            }
            if `wdmissing' {
                local colloc = `cmdwidth' + 2
                di as error " (directory not found)" as text ""
            }
            else display
        }
    } // file loop

*    if "`details'"=="" {
*        di _new as text "Use " as result "listcd, details" ///
*            as text " to list " as result "S_cd*" as text " macros"
*    }

//  restore starting working directory

    quietly cd `"`currentpwd'"'

end
exit
* cdlist.ado v0.2.0 Scott Long 2017-07-27
* cdlist.ado v0.3.0 Scott Long 2017-07-30 add cdinfo
* cdlist.ado v0.4.0 Scott Long 2017-07-30
* cdlist.ado v0.5.0 Scott Long 2017-07-30 // links to commands
* cdlist.ado v0.5.1 Scott Long 2017-08-09
* cdlist.ado v0.6.0 Scott Long 2017-08-13
* listcd.ado v0.7.0 Scott Long 2017-09-07
* v0.8.2 2018-01-04 - delete default
* v0.8.1 2017-09-11 Scott Long  - workingdir.pkg
* v0.8.0 2017-09-11 Scott Long  - workingdir.pkg

/*
*    decodeit `*'
capture program drop decodeit
program define decodeit
    syntax , [ DETails DIRectories PATHs NODELete hold]
    if "`nodelete'"=="" local delete delete
    if "`paths'"!="" local directories directories
    c_local details `details'
    c_local directories `directories'
    c_local delete `delete'
    c_local hold `hold'
end
*/