2022-04-23 03:56:57 +00:00
|
|
|
local commander = require 'commander'
|
|
|
|
local fs = require 'fs'
|
|
|
|
local lunacolors = require 'lunacolors'
|
|
|
|
local dirs = require 'nature.dirs'
|
|
|
|
|
2023-01-20 22:35:10 +00:00
|
|
|
commander.register('cdr', function(args, sinks)
|
2022-04-23 03:56:57 +00:00
|
|
|
if not args[1] then
|
2023-01-20 22:35:10 +00:00
|
|
|
sinks.out:writeln(lunacolors.format [[
|
2022-04-23 03:56:57 +00:00
|
|
|
cdr: change directory to one which has been recently visied
|
|
|
|
|
|
|
|
usage: cdr <index>
|
|
|
|
|
|
|
|
to get a list of recent directories, use {green}{underline}cdr list{reset}]])
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if args[1] == 'list' then
|
|
|
|
local recentDirs = dirs.recentDirs
|
|
|
|
if #recentDirs == 0 then
|
2023-01-20 22:35:10 +00:00
|
|
|
sinks.out:writeln 'No directories have been visited.'
|
2022-04-23 03:56:57 +00:00
|
|
|
return 1
|
|
|
|
end
|
2023-01-20 22:35:10 +00:00
|
|
|
sinks.out:writeln(table.concat(recentDirs, '\n'))
|
2022-04-23 03:56:57 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local index = tonumber(args[1])
|
|
|
|
if not index then
|
2023-01-20 22:35:10 +00:00
|
|
|
sinks.out:writeln(string.format('Received %s as index, which isn\'t a number.', index))
|
2022-04-23 03:56:57 +00:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if not dirs.recent(index) then
|
2023-01-20 22:35:10 +00:00
|
|
|
sinks.out:writeln(string.format('No recent directory found at index %s.', index))
|
2022-04-23 03:56:57 +00:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
fs.cd(dirs.recent(index))
|
|
|
|
end)
|