mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	fix(commands/cd): set oldpwd when cd-ing with no args (fixes #225)
This commit is contained in:
		
							parent
							
								
									97188e73a5
								
							
						
					
					
						commit
						c2db9e65fa
					
				@ -8,28 +8,21 @@ commander.register('cd', function (args)
 | 
				
			|||||||
	if #args > 1 then
 | 
						if #args > 1 then
 | 
				
			||||||
		print("cd: too many arguments")
 | 
							print("cd: too many arguments")
 | 
				
			||||||
		return 1
 | 
							return 1
 | 
				
			||||||
	elseif #args > 0 then
 | 
					 | 
				
			||||||
		local path = args[1]:gsub('$%$','\0'):gsub('${([%w_]+)}', os.getenv)
 | 
					 | 
				
			||||||
		:gsub('$([%w_]+)', os.getenv):gsub('%z','$'):gsub('^%s*(.-)%s*$', '%1')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if path == '-' then
 | 
					 | 
				
			||||||
			path = dirs.old
 | 
					 | 
				
			||||||
            print(path)
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
        dirs.setOld(hilbish.cwd())
 | 
					 | 
				
			||||||
		dirs.push(path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		local ok, err = pcall(function() fs.cd(path) end)
 | 
					 | 
				
			||||||
		if not ok then
 | 
					 | 
				
			||||||
			print(err)
 | 
					 | 
				
			||||||
			return 1
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
		bait.throw('cd', path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	fs.cd(hilbish.home)
 | 
					 | 
				
			||||||
	bait.throw('cd', hilbish.home)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dirs.push(hilbish.home)
 | 
						local path = args[1] and args[1] or hilbish.home
 | 
				
			||||||
 | 
						if path == '-' then
 | 
				
			||||||
 | 
							path = dirs.old
 | 
				
			||||||
 | 
							print(path)
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dirs.setOld(hilbish.cwd())
 | 
				
			||||||
 | 
						dirs.push(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						local ok, err = pcall(function() fs.cd(path) end)
 | 
				
			||||||
 | 
						if not ok then
 | 
				
			||||||
 | 
							print(err)
 | 
				
			||||||
 | 
							return 1
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						bait.throw('cd', path)
 | 
				
			||||||
end)
 | 
					end)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user