mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:52:45 +00:00 
			
		
		
		
	 d0fb816ac3
			
		
	
	
		d0fb816ac3
		
	
	
	
	
		
			
			`cdh` with no arguments dumps the last 8 cd calls in history, and `cdh [index]` can be used to cd to re-run a specific index from that history. `cdh` itself it a thin wrapper of the `cd` builtin. There's definitely some improvements that can be made for this command, but this seems like a good starting point for getting a feel for it and ideas for changing it in the future. It's not entirely clear whether we should be storing the resolved path - or simply just the last argument passed to cd. For now we just use the last path passed into cd as this seemed like the better option for now. This means: * invalid paths will still be stored in history (potentially useful) * cdh's can be repeated for duplicate directory names * the history looks a little nicer on the eyes It might make sense to use resolved paths. Closes #397
		
			
				
	
	
		
			50 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  * All rights reserved.
 | |
|  *
 | |
|  * Redistribution and use in source and binary forms, with or without
 | |
|  * modification, are permitted provided that the following conditions are met:
 | |
|  *
 | |
|  * 1. Redistributions of source code must retain the above copyright notice, this
 | |
|  *    list of conditions and the following disclaimer.
 | |
|  *
 | |
|  * 2. Redistributions in binary form must reproduce the above copyright notice,
 | |
|  *    this list of conditions and the following disclaimer in the documentation
 | |
|  *    and/or other materials provided with the distribution.
 | |
|  *
 | |
|  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | |
|  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 | |
|  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | |
|  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 | |
|  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 | |
|  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 | |
|  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 | |
|  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 | |
|  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | |
|  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/String.h>
 | |
| #include <AK/Vector.h>
 | |
| #include <AK/CircularQueue.h>
 | |
| #include <termios.h>
 | |
| 
 | |
| struct GlobalState {
 | |
|     String cwd;
 | |
|     String username;
 | |
|     String home;
 | |
|     char ttyname[32];
 | |
|     char hostname[32];
 | |
|     uid_t uid;
 | |
|     struct termios termios;
 | |
|     struct termios default_termios;
 | |
|     bool was_interrupted { false };
 | |
|     bool was_resized { false };
 | |
|     int last_return_code { 0 };
 | |
|     Vector<String> directory_stack;
 | |
|     CircularQueue<String, 8> cd_history; // FIXME: have a configurable cd history length
 | |
| };
 | |
| 
 | |
| extern GlobalState g;
 |