Compare commits
	
		
			151 Commits
		
	
	
		
			2c595100ae
			...
			master
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						977d1a7120
	
				 | 
					
					
						|||
| 
						
						
							
						
						9b274417c5
	
				 | 
					
					
						|||
| 
						
						
							
						
						cc14a9f735
	
				 | 
					
					
						|||
| 
						
						
							
						
						b070df6010
	
				 | 
					
					
						|||
| 
						
						
							
						
						3075d47aeb
	
				 | 
					
					
						|||
| 
						
						
							
						
						85b2d8a2ee
	
				 | 
					
					
						|||
| 
						
						
							
						
						272ee62ad8
	
				 | 
					
					
						|||
| 
						
						
							
						
						a85426541a
	
				 | 
					
					
						|||
| 
						
						
							
						
						c9b003735d
	
				 | 
					
					
						|||
| 
						
						
							
						
						52a28f01c8
	
				 | 
					
					
						|||
| 
						
						
							
						
						3607757554
	
				 | 
					
					
						|||
| 
						
						
							
						
						6eb216a40a
	
				 | 
					
					
						|||
| 
						
						
							
						
						9ce6f47716
	
				 | 
					
					
						|||
| 
						
						
							
						
						c9662f1a7b
	
				 | 
					
					
						|||
| 
						
						
							
						
						9ddeb03652
	
				 | 
					
					
						|||
| 
						
						
							
						
						acb187c6b1
	
				 | 
					
					
						|||
| 
						
						
							
						
						9427df62e7
	
				 | 
					
					
						|||
| 
						
						
							
						
						4d6999c415
	
				 | 
					
					
						|||
| 
						
						
							
						
						30ed61fdd2
	
				 | 
					
					
						|||
| 
						
						
							
						
						2df916c9b3
	
				 | 
					
					
						|||
| 
						
						
							
						
						24401825b4
	
				 | 
					
					
						|||
| 
						
						
							
						
						2bfb490798
	
				 | 
					
					
						|||
| 
						
						
							
						
						338d00d605
	
				 | 
					
					
						|||
| 
						
						
							
						
						015652e379
	
				 | 
					
					
						|||
| 
						
						
							
						
						c298b6fc97
	
				 | 
					
					
						|||
| 
						
						
							
						
						7c2ab8ab59
	
				 | 
					
					
						|||
| 
						
						
							
						
						e423a3a1b1
	
				 | 
					
					
						|||
| 
						
						
							
						
						916f354c9b
	
				 | 
					
					
						|||
| 
						
						
							
						
						050f875c47
	
				 | 
					
					
						|||
| 
						
						
							
						
						aeffe40efc
	
				 | 
					
					
						|||
| 
						
						
							
						
						536aa57761
	
				 | 
					
					
						|||
| 
						
						
							
						
						0d10ae06e6
	
				 | 
					
					
						|||
| 
						
						
							
						
						e1b0831854
	
				 | 
					
					
						|||
| 
						
						
							
						
						4e93dfbb8d
	
				 | 
					
					
						|||
| 
						
						
							
						
						8a6bb54eb5
	
				 | 
					
					
						|||
| 
						
						
							
						
						4ef7c9edf7
	
				 | 
					
					
						|||
| 
						
						
							
						
						3eea106c3c
	
				 | 
					
					
						|||
| 
						
						
							
						
						7de8c84e8f
	
				 | 
					
					
						|||
| 
						
						
							
						
						e17c5e2083
	
				 | 
					
					
						|||
| 
						
						
							
						
						9bd3739122
	
				 | 
					
					
						|||
| 
						
						
							
						
						ec1f1031cc
	
				 | 
					
					
						|||
| 
						
						
							
						
						bc99b3dd48
	
				 | 
					
					
						|||
| 
						
						
							
						
						e948741864
	
				 | 
					
					
						|||
| 
						
						
							
						
						0adbac2066
	
				 | 
					
					
						|||
| 
						
						
							
						
						2238db5a4e
	
				 | 
					
					
						|||
| 
						
						
							
						
						98612f5492
	
				 | 
					
					
						|||
| 
						
						
							
						
						1034321f81
	
				 | 
					
					
						|||
| 
						
						
							
						
						e7da32160c
	
				 | 
					
					
						|||
| 
						
						
							
						
						fdb338fe12
	
				 | 
					
					
						|||
| 
						
						
							
						
						9056ef4194
	
				 | 
					
					
						|||
| 
						
						
							
						
						b8a4742fb9
	
				 | 
					
					
						|||
| 
						
						
							
						
						c999e5a8e4
	
				 | 
					
					
						|||
| 
						
						
							
						
						07ef834a1e
	
				 | 
					
					
						|||
| 
						
						
							
						
						997f5c25a2
	
				 | 
					
					
						|||
| 
						
						
							
						
						39e68a977c
	
				 | 
					
					
						|||
| 
						
						
							
						
						c20d3780b2
	
				 | 
					
					
						|||
| 
						
						
							
						
						22725ba3b7
	
				 | 
					
					
						|||
| 
						
						
							
						
						df046bb071
	
				 | 
					
					
						|||
| 
						
						
							
						
						0c1a8d9902
	
				 | 
					
					
						|||
| 
						
						
							
						
						cc59fcfb41
	
				 | 
					
					
						|||
| 
						
						
							
						
						c88566e7bb
	
				 | 
					
					
						|||
| 
						
						
							
						
						39c840cd74
	
				 | 
					
					
						|||
| 
						
						
							
						
						f231828e8d
	
				 | 
					
					
						|||
| 
						
						
							
						
						1318c4983f
	
				 | 
					
					
						|||
| 
						
						
							
						
						c503954f44
	
				 | 
					
					
						|||
| 
						
						
							
						
						77973fc026
	
				 | 
					
					
						|||
| 
						
						
							
						
						61be9528e4
	
				 | 
					
					
						|||
| 
						
						
							
						
						2313485970
	
				 | 
					
					
						|||
| 
						
						
							
						
						20c883fb8a
	
				 | 
					
					
						|||
| 
						
						
							
						
						bbf97f6d3d
	
				 | 
					
					
						|||
| 
						
						
							
						
						706795c85c
	
				 | 
					
					
						|||
| 
						
						
							
						
						e8eaa2366a
	
				 | 
					
					
						|||
| 
						
						
							
						
						12d8f6a931
	
				 | 
					
					
						|||
| 
						
						
							
						
						5d0c105b10
	
				 | 
					
					
						|||
| 
						
						
							
						
						33a8e26efc
	
				 | 
					
					
						|||
| 
						
						
							
						
						bbd23187bc
	
				 | 
					
					
						|||
| 
						
						
							
						
						a0eacf4607
	
				 | 
					
					
						|||
| 
						
						
							
						
						37ad5f43df
	
				 | 
					
					
						|||
| 
						
						
							
						
						a95fa2f96d
	
				 | 
					
					
						|||
| 
						
						
							
						
						6f40b8db3a
	
				 | 
					
					
						|||
| 
						
						
							
						
						63e7895905
	
				 | 
					
					
						|||
| 
						
						
							
						
						6aa4bd2ff5
	
				 | 
					
					
						|||
| 
						
						
							
						
						000315165d
	
				 | 
					
					
						|||
| 
						
						
							
						
						d2e4b91262
	
				 | 
					
					
						|||
| 
						
						
							
						
						c18630295c
	
				 | 
					
					
						|||
| 
						
						
							
						
						b53a3a0981
	
				 | 
					
					
						|||
| 
						
						
							
						
						cf80a15501
	
				 | 
					
					
						|||
| 
						
						
							
						
						2d6d0582a1
	
				 | 
					
					
						|||
| 
						
						
							
						
						5451eba2a3
	
				 | 
					
					
						|||
| 
						
						
							
						
						b8c767354e
	
				 | 
					
					
						|||
| 
						
						
							
						
						c07f557c16
	
				 | 
					
					
						|||
| 
						
						
							
						
						5fff336e77
	
				 | 
					
					
						|||
| 
						
						
							
						
						6e8d816ada
	
				 | 
					
					
						|||
| 
						
						
							
						
						063938ff60
	
				 | 
					
					
						|||
| 
						
						
							
						
						93172797e1
	
				 | 
					
					
						|||
| 
						
						
							
						
						1507f2dff9
	
				 | 
					
					
						|||
| 
						
						
							
						
						9a12fd8021
	
				 | 
					
					
						|||
| 
						
						
							
						
						f596bb8f5e
	
				 | 
					
					
						|||
| 
						
						
							
						
						67da8d965b
	
				 | 
					
					
						|||
| 
						
						
							
						
						e60ffeeb20
	
				 | 
					
					
						|||
| 
						
						
							
						
						9a2f6ab5cf
	
				 | 
					
					
						|||
| 
						
						
							
						
						0a66ae4d26
	
				 | 
					
					
						|||
| 
						
						
							
						
						121d7850fe
	
				 | 
					
					
						|||
| 
						
						
							
						
						98c8dc5b7d
	
				 | 
					
					
						|||
| 
						
						
							
						
						b99f96cf6a
	
				 | 
					
					
						|||
| 
						
						
							
						
						5759df156b
	
				 | 
					
					
						|||
| 
						
						
							
						
						91df92f49a
	
				 | 
					
					
						|||
| 
						
						
							
						
						bff886841b
	
				 | 
					
					
						|||
| 
						
						
							
						
						ebb444dda1
	
				 | 
					
					
						|||
| 
						
						
							
						
						da0252ff98
	
				 | 
					
					
						|||
| 
						
						
							
						
						98da5f6d35
	
				 | 
					
					
						|||
| 
						
						
							
						
						f4eebf59af
	
				 | 
					
					
						|||
| 
						
						
							
						
						63982b3754
	
				 | 
					
					
						|||
| 
						
						
							
						
						d6eaf44aee
	
				 | 
					
					
						|||
| 
						
						
							
						
						b8344f215c
	
				 | 
					
					
						|||
| 
						
						
							
						
						623c4914d1
	
				 | 
					
					
						|||
| 
						
						
							
						
						c0f0328762
	
				 | 
					
					
						|||
| 
						
						
							
						
						571ec74706
	
				 | 
					
					
						|||
| 
						
						
							
						
						7cce0cc2fd
	
				 | 
					
					
						|||
| 
						
						
							
						
						bf38e4e9ea
	
				 | 
					
					
						|||
| 
						
						
							
						
						2c847fb4a3
	
				 | 
					
					
						|||
| 
						
						
							
						
						296c0cc66f
	
				 | 
					
					
						|||
| 
						
						
							
						
						71fbaca9e5
	
				 | 
					
					
						|||
| 
						
						
							
						
						4ce6454ebb
	
				 | 
					
					
						|||
| 
						
						
							
						
						315b662581
	
				 | 
					
					
						|||
| 
						
						
							
						
						4a2a49312b
	
				 | 
					
					
						|||
| 
						
						
							
						
						7174b507d3
	
				 | 
					
					
						|||
| 
						
						
							
						
						aae9c392fa
	
				 | 
					
					
						|||
| 
						
						
							
						
						fad0d264a5
	
				 | 
					
					
						|||
| 
						
						
							
						
						473aa8788c
	
				 | 
					
					
						|||
| 
						
						
							
						
						85ada4dd2b
	
				 | 
					
					
						|||
| 
						
						
							
						
						e6ed7da395
	
				 | 
					
					
						|||
| 
						
						
							
						
						c065238e75
	
				 | 
					
					
						|||
| 
						
						
							
						
						579e4c9a34
	
				 | 
					
					
						|||
| 
						
						
							
						
						3c056dde91
	
				 | 
					
					
						|||
| 
						
						
							
						
						081b4db5c3
	
				 | 
					
					
						|||
| 
						
						
							
						
						36454fb90c
	
				 | 
					
					
						|||
| 
						
						
							
						
						6b1ff048b8
	
				 | 
					
					
						|||
| 
						
						
							
						
						3790f8dfa0
	
				 | 
					
					
						|||
| 
						
						
							
						
						5c086016b5
	
				 | 
					
					
						|||
| 
						
						
							
						
						232ecffa2d
	
				 | 
					
					
						|||
| 
						
						
							
						
						f3fffe4b25
	
				 | 
					
					
						|||
| 
						
						
							
						
						77313663a3
	
				 | 
					
					
						|||
| 
						
						
							
						
						5f2eaa88e0
	
				 | 
					
					
						|||
| 
						
						
							
						
						d6846e6327
	
				 | 
					
					
						|||
| 
						
						
							
						
						314ba114a1
	
				 | 
					
					
						|||
| 
						
						
							
						
						4de89faf7e
	
				 | 
					
					
						|||
| 
						
						
							
						
						beee2e2683
	
				 | 
					
					
						|||
| 
						
						
							
						
						4ab0db3c04
	
				 | 
					
					
						|||
| 
						
						
							
						
						3624636c2f
	
				 | 
					
					
						|||
| 
						
						
							
						
						e80c56e249
	
				 | 
					
					
						
							
								
								
									
										14
									
								
								.clang-format
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								.clang-format
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
BasedOnStyle: LLVM
 | 
			
		||||
ColumnLimit: 80
 | 
			
		||||
IndentWidth: 4
 | 
			
		||||
TabWidth: 4
 | 
			
		||||
UseTab: ForContinuationAndIndentation
 | 
			
		||||
SpaceAfterCStyleCast: true
 | 
			
		||||
SpaceBeforeParens: Always
 | 
			
		||||
AlignAfterOpenBracket: DontAlign
 | 
			
		||||
AlignEscapedNewlines: DontAlign
 | 
			
		||||
AlignOperands: DontAlign
 | 
			
		||||
AlignConsecutiveMacros: Consecutive
 | 
			
		||||
BreakBeforeTernaryOperators: true
 | 
			
		||||
SpacesBeforeTrailingComments: 2
 | 
			
		||||
WhitespaceSensitiveMacros: ['XX', 'ACTIONS', 'LS']
 | 
			
		||||
@@ -1,46 +1,55 @@
 | 
			
		||||
# target_compile_features has been introduced in that version
 | 
			
		||||
cmake_minimum_required (VERSION 3.1.0)
 | 
			
		||||
 | 
			
		||||
project (sdn CXX)
 | 
			
		||||
set (version 0.1)
 | 
			
		||||
cmake_minimum_required (VERSION 3.1...3.27)
 | 
			
		||||
project (sdn VERSION 1.0 LANGUAGES CXX)
 | 
			
		||||
 | 
			
		||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
 | 
			
		||||
	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
# Since we use a language with slow compilers, let's at least use a fast linker
 | 
			
		||||
execute_process (COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version
 | 
			
		||||
	ERROR_QUIET OUTPUT_VARIABLE ld_version)
 | 
			
		||||
if ("${ld_version}" MATCHES "GNU gold")
 | 
			
		||||
	set (CMAKE_EXE_LINKER_FLAGS "-fuse-ld=gold ${CMAKE_EXE_LINKER_FLAGS}")
 | 
			
		||||
	set (CMAKE_CXX_FLAGS
 | 
			
		||||
		"${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-misleading-indentation -pedantic")
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
find_package (PkgConfig REQUIRED)
 | 
			
		||||
pkg_check_modules (NCURSESW QUIET ncursesw)
 | 
			
		||||
pkg_check_modules (ACL libacl)
 | 
			
		||||
pkg_check_modules (NCURSESW ncursesw)
 | 
			
		||||
if (NOT NCURSESW_FOUND)
 | 
			
		||||
	find_library (NCURSESW_LIBRARIES NAMES ncursesw)
 | 
			
		||||
	find_path (NCURSESW_INCLUDE_DIRS ncurses.h PATH_SUFFIXES ncurses)
 | 
			
		||||
endif ()
 | 
			
		||||
 | 
			
		||||
add_executable (${PROJECT_NAME} ${PROJECT_NAME}.cpp)
 | 
			
		||||
target_include_directories (${PROJECT_NAME} PUBLIC ${NCURSESW_INCLUDE_DIRS})
 | 
			
		||||
target_link_libraries (${PROJECT_NAME} PUBLIC ${NCURSESW_LIBRARIES} acl)
 | 
			
		||||
target_include_directories (${PROJECT_NAME}
 | 
			
		||||
	PUBLIC ${NCURSESW_INCLUDE_DIRS} ${ACL_INCLUDE_DIRS})
 | 
			
		||||
target_link_directories (${PROJECT_NAME}
 | 
			
		||||
	PUBLIC ${NCURSESW_LIBRARY_DIRS} ${ACL_LIBRARY_DIRS})
 | 
			
		||||
target_link_libraries (${PROJECT_NAME}
 | 
			
		||||
	PUBLIC ${NCURSESW_LIBRARIES} ${ACL_LIBRARIES})
 | 
			
		||||
target_compile_features (${PROJECT_NAME} PUBLIC cxx_std_14)
 | 
			
		||||
target_compile_definitions (${PROJECT_NAME} PUBLIC
 | 
			
		||||
	-DPROJECT_NAME=\"${PROJECT_NAME}\" -DPROJECT_VERSION=\"${version}\")
 | 
			
		||||
	-DPROJECT_NAME=\"${PROJECT_NAME}\" -DPROJECT_VERSION=\"${PROJECT_VERSION}\")
 | 
			
		||||
 | 
			
		||||
add_executable (${PROJECT_NAME}-mc-ext ${PROJECT_NAME}-mc-ext.cpp)
 | 
			
		||||
target_compile_features (${PROJECT_NAME}-mc-ext PUBLIC cxx_std_17)
 | 
			
		||||
 | 
			
		||||
include (GNUInstallDirs)
 | 
			
		||||
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
 | 
			
		||||
# sdn-mc-ext should be in libexec, but we prefer it in PATH.
 | 
			
		||||
install (TARGETS sdn sdn-mc-ext
 | 
			
		||||
	DESTINATION ${CMAKE_INSTALL_BINDIR})
 | 
			
		||||
install (PROGRAMS sdn-install sdn-view
 | 
			
		||||
	DESTINATION ${CMAKE_INSTALL_BINDIR})
 | 
			
		||||
install (FILES sdn.1 sdn-install.1 sdn-view.1
 | 
			
		||||
	DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
 | 
			
		||||
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
 | 
			
		||||
 | 
			
		||||
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Directory navigator")
 | 
			
		||||
set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
 | 
			
		||||
set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p@janouch.name>")
 | 
			
		||||
set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
 | 
			
		||||
set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
 | 
			
		||||
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
 | 
			
		||||
set (CPACK_PACKAGE_VERSION ${version})
 | 
			
		||||
set (CPACK_GENERATOR "TGZ;ZIP")
 | 
			
		||||
set (CPACK_PACKAGE_FILE_NAME
 | 
			
		||||
	"${PROJECT_NAME}-${version}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
 | 
			
		||||
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${version}")
 | 
			
		||||
	"${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
 | 
			
		||||
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${PROJECT_VERSION}")
 | 
			
		||||
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
 | 
			
		||||
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
 | 
			
		||||
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${version}")
 | 
			
		||||
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
 | 
			
		||||
 | 
			
		||||
set (CPACK_SET_DESTDIR TRUE)
 | 
			
		||||
include (CPack)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
Copyright (c) 2017 - 2018, Přemysl Janouch <p@janouch.name>
 | 
			
		||||
Copyright (c) 2017 - 2024, Přemysl Eric Janouch <p@janouch.name>
 | 
			
		||||
 | 
			
		||||
Permission to use, copy, modify, and/or distribute this software for any
 | 
			
		||||
purpose with or without fee is hereby granted.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,12 +1,19 @@
 | 
			
		||||
.POSIX:
 | 
			
		||||
SHELL = /bin/sh
 | 
			
		||||
CXXFLAGS = -g -std=c++14 -Wall -Wextra -pedantic -static-libstdc++
 | 
			
		||||
CXXFLAGS = -g -std=c++14 -Wall -Wextra -Wno-misleading-indentation -pedantic
 | 
			
		||||
CPPFLAGS = `sed -ne '/^project (\([^ )]*\) VERSION \([^ )]*\).*/ \
 | 
			
		||||
	s//-DPROJECT_NAME="\1" -DPROJECT_VERSION="\2"/p' CMakeLists.txt`
 | 
			
		||||
 | 
			
		||||
all: sdn
 | 
			
		||||
%: %.cpp CMakeLists.txt
 | 
			
		||||
	$(CXX) $(CXXFLAGS) $< -o $@ `pkg-config --libs --cflags ncursesw` -lacl \
 | 
			
		||||
	`sed -ne 's/^project (\([^ )]*\).*/-DPROJECT_NAME="\1"/p' \
 | 
			
		||||
	-e 's/^set (version \([^ )]*\).*/-DPROJECT_VERSION="\1"/p' CMakeLists.txt`
 | 
			
		||||
sdn: sdn.cpp CMakeLists.txt
 | 
			
		||||
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o $@ \
 | 
			
		||||
	-lacl `pkg-config --libs --cflags ncursesw`
 | 
			
		||||
sdn-static: sdn.cpp CMakeLists.txt
 | 
			
		||||
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o $@ \
 | 
			
		||||
	-static-libstdc++ \
 | 
			
		||||
	-Wl,--start-group,-Bstatic \
 | 
			
		||||
	-lacl `pkg-config --static --libs --cflags ncursesw` \
 | 
			
		||||
	-Wl,--end-group,-Bdynamic
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f sdn
 | 
			
		||||
	rm -f sdn sdn-static
 | 
			
		||||
 | 
			
		||||
.PHONY: all clean
 | 
			
		||||
.PHONY: clean
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								NEWS
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								NEWS
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
Unreleased
 | 
			
		||||
 | 
			
		||||
 * Added selection functionality, and adjusted key bindings:
 | 
			
		||||
    - C-t or Insert toggle whether the current item is selected;
 | 
			
		||||
    - + and - adjust the selection using shell globs;
 | 
			
		||||
    - t and T insert the selection into the external command line
 | 
			
		||||
      in relative or absolute form, respectively;
 | 
			
		||||
	- Enter is like t but enters directories, and M-Enter is synonymous to t;
 | 
			
		||||
    - C-g or Escape clear the selection, similarly to the editor.
 | 
			
		||||
 | 
			
		||||
 * Added an sdn-view script that can process Midnight Commander mc.ext.ini files
 | 
			
		||||
   and apply matching filters; this script has been made the default F3 binding,
 | 
			
		||||
   while the original direct pager invocation has been moved to F13 (which also
 | 
			
		||||
   reflects Midnight Commander)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
1.0.0 (2024-12-21)
 | 
			
		||||
 | 
			
		||||
 * Initial release
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										124
									
								
								README.adoc
									
									
									
									
									
								
							
							
						
						
									
										124
									
								
								README.adoc
									
									
									
									
									
								
							@@ -5,21 +5,35 @@ sdn
 | 
			
		||||
'sdn' is a simple directory navigator that you can invoke while editing shell
 | 
			
		||||
commands.  It enables you to:
 | 
			
		||||
 | 
			
		||||
 * take a quick peek at directory contents without running `ls`
 | 
			
		||||
 * take a quick peek at directory contents without running `ls`;
 | 
			
		||||
 * select files to insert into the command line;
 | 
			
		||||
 * browse the filesystem without all the mess that Midnight Commander does:
 | 
			
		||||
   there's no need to create a subshell in a new pty.  The current command line
 | 
			
		||||
   can be simply forwarded if it is to be edited.  What's more, it will always
 | 
			
		||||
   be obvious whether the navigator is running.
 | 
			
		||||
 | 
			
		||||
Development has just started and the only supported platform is Linux.
 | 
			
		||||
I wanted to try a different, simpler approach here.
 | 
			
		||||
'sdn' runs on Linux and all BSD derivatives.  I wanted to try a different,
 | 
			
		||||
simpler approach here, and the end result is very friendly to tinkering.
 | 
			
		||||
 | 
			
		||||
image::sdn.png[align="center"]
 | 
			
		||||
 | 
			
		||||
Packages
 | 
			
		||||
--------
 | 
			
		||||
Regular releases are sporadic.  git master should be stable enough.
 | 
			
		||||
You can get a package with the latest development version using Arch Linux's
 | 
			
		||||
https://aur.archlinux.org/packages/sdn-git[AUR],
 | 
			
		||||
or as a https://git.janouch.name/p/nixexprs[Nix derivation].
 | 
			
		||||
 | 
			
		||||
Building
 | 
			
		||||
--------
 | 
			
		||||
Build dependencies: CMake and/or make, a C++14 compiler, pkg-config +
 | 
			
		||||
Runtime dependencies: ncursesw
 | 
			
		||||
Build dependencies: CMake and/or make, a C++17 compiler, pkg-config +
 | 
			
		||||
Runtime dependencies: ncursesw, libacl (on Linux)
 | 
			
		||||
 | 
			
		||||
 $ git clone https://github.com/pjanouch/sdn.git
 | 
			
		||||
// Working around libasciidoc's missing support for escaping it like \++
 | 
			
		||||
Unfortunately most LLVM libc{plus}{plus} versions have a bug that crashes 'sdn'
 | 
			
		||||
on start.  Use GNU libstdc{plus}{plus} if you're affected.
 | 
			
		||||
 | 
			
		||||
 $ git clone https://git.janouch.name/p/sdn.git
 | 
			
		||||
 $ mkdir sdn/build
 | 
			
		||||
 $ cd sdn/build
 | 
			
		||||
 $ cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug
 | 
			
		||||
@@ -37,64 +51,68 @@ Or you can try telling CMake to make a package for you.  For Debian it is:
 | 
			
		||||
There is also a Makefile you can use to quickly build a binary to be copied
 | 
			
		||||
into the PATH of any machine you want to have 'sdn' on.
 | 
			
		||||
 | 
			
		||||
zsh
 | 
			
		||||
---
 | 
			
		||||
To start using this navigator, put the following in your .zshrc:
 | 
			
		||||
....
 | 
			
		||||
sdn-navigate () {
 | 
			
		||||
  # ... possibly zle-line-init
 | 
			
		||||
  eval `sdn`
 | 
			
		||||
  [ -z "$cd" ] || cd "$cd"
 | 
			
		||||
  [ -z "$insert" ] || LBUFFER="$LBUFFER$insert "
 | 
			
		||||
  zle reset-prompt
 | 
			
		||||
  # ... possibly zle-line-finish
 | 
			
		||||
}
 | 
			
		||||
zle -N sdn-navigate
 | 
			
		||||
bindkey '\eo' sdn-navigate
 | 
			
		||||
....
 | 
			
		||||
Configuration
 | 
			
		||||
-------------
 | 
			
		||||
For a slightly more technical explanation please refer to manual pages.
 | 
			
		||||
 | 
			
		||||
bash
 | 
			
		||||
----
 | 
			
		||||
Here we can't reset the prompt from within a `bind -x` handler but there is
 | 
			
		||||
an acceptable workaround:
 | 
			
		||||
....
 | 
			
		||||
sdn-navigate () {
 | 
			
		||||
  SDN_L=$READLINE_LINE SDN_P=$READLINE_POINT
 | 
			
		||||
  READLINE_LINE=
 | 
			
		||||
Integration
 | 
			
		||||
~~~~~~~~~~~
 | 
			
		||||
The package contains an installation script called 'sdn-install' which will bind
 | 
			
		||||
'sdn' to Alt-o in your shell's initialisation file.  The supported shells are:
 | 
			
		||||
 | 
			
		||||
  eval `sdn`
 | 
			
		||||
  [[ -z "$cd" ]] || cd "$cd"
 | 
			
		||||
  [[ -z "$insert" ]] || {
 | 
			
		||||
    SDN_L="${SDN_L:0:$SDN_P}$insert ${SDN_L:$SDN_P}"
 | 
			
		||||
    ((SDN_P=SDN_P+${#insert}+1))
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
sdn-restore () {
 | 
			
		||||
  READLINE_LINE=$SDN_L READLINE_POINT=$SDN_P
 | 
			
		||||
  unset SDN_L SDN_P
 | 
			
		||||
}
 | 
			
		||||
 - *zsh*: works well
 | 
			
		||||
 - *bash*: minor issue: exiting the navigator confirms an empty prompt
 | 
			
		||||
 - *fish*: works well
 | 
			
		||||
 - *elvish*: version 0.14.1 and above, an unstable API is used, works well
 | 
			
		||||
+
 | 
			
		||||
elvish is absolutely perverse.  And so is integrating 'sdn' into it because it
 | 
			
		||||
already includes a custom file manager, bound to Ctrl-N (though I find the
 | 
			
		||||
ranger-like interface confusing and resource-demanding).
 | 
			
		||||
 | 
			
		||||
bind -x '"\200": sdn-navigate'
 | 
			
		||||
bind -x '"\201": sdn-restore'
 | 
			
		||||
bind '"\eo":"\200\C-m\201"'
 | 
			
		||||
....
 | 
			
		||||
 | 
			
		||||
Colors
 | 
			
		||||
------
 | 
			
		||||
Colours
 | 
			
		||||
~~~~~~~
 | 
			
		||||
Here is an example of a '~/.config/sdn/look' file; the format is similar to
 | 
			
		||||
that of git, only named colors aren't supported:
 | 
			
		||||
that of git, only named colours aren't supported:
 | 
			
		||||
 | 
			
		||||
....
 | 
			
		||||
cursor 231 202
 | 
			
		||||
select 202 bold
 | 
			
		||||
bar 16 255 ul
 | 
			
		||||
cwd bold
 | 
			
		||||
input
 | 
			
		||||
cmdline 145
 | 
			
		||||
....
 | 
			
		||||
 | 
			
		||||
Similar software
 | 
			
		||||
----------------
 | 
			
		||||
 * https://elvish.io/ is an entire shell with an integrated ranger-like file
 | 
			
		||||
   manager on Ctrl-N (I find this confusing and resource-demanding, preferring
 | 
			
		||||
   to keep closer to "orthodox file managers")
 | 
			
		||||
Filename colours are taken from the `LS_COLORS` environment variable.
 | 
			
		||||
Run `dircolors` to get some defaults.
 | 
			
		||||
 | 
			
		||||
Bindings
 | 
			
		||||
~~~~~~~~
 | 
			
		||||
To obtain more vifm-like controls, you may write the following to your
 | 
			
		||||
'~/.config/sdn/bindings' file:
 | 
			
		||||
 | 
			
		||||
....
 | 
			
		||||
normal h parent
 | 
			
		||||
normal l enter
 | 
			
		||||
....
 | 
			
		||||
 | 
			
		||||
Helper programs
 | 
			
		||||
~~~~~~~~~~~~~~~
 | 
			
		||||
The F3, F13 and F4 keys are normally bound to actions 'view', 'view-raw',
 | 
			
		||||
and 'edit', similarly to Norton Commander and other orthodox file managers.
 | 
			
		||||
The helper programs used here may be changed by setting the PAGER and VISUAL
 | 
			
		||||
(or EDITOR) environment variables.
 | 
			
		||||
 | 
			
		||||
If 'view' finds Midnight Commander, it will make use of its configuration
 | 
			
		||||
to apply any matching filter, such as to produce archive listings,
 | 
			
		||||
or it will run the respective command.
 | 
			
		||||
 | 
			
		||||
While it is mostly possible to get 'mcview' working using an invocation like
 | 
			
		||||
`PAGER='mcview -u' sdn`, beware that this helper cannot read files from its
 | 
			
		||||
standard input, nor does it enable overstrike processing by default (F9, could
 | 
			
		||||
be hacked around in 'mc.ext' by turning on the `nroff` switch for a custom file
 | 
			
		||||
extension, just without actually invoking 'nroff'), and thus it can't show the
 | 
			
		||||
program help.  'sdn' is currently optimised for 'less' as the pager.
 | 
			
		||||
 | 
			
		||||
Contributing and Support
 | 
			
		||||
------------------------
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										182
									
								
								sdn-install
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										182
									
								
								sdn-install
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,182 @@
 | 
			
		||||
#!/bin/sh -e
 | 
			
		||||
# sdn-install: integrate sdn with the shell, binding to M-o
 | 
			
		||||
# vim: set sw=2 ts=2 sts=2 et tw=80:
 | 
			
		||||
 | 
			
		||||
zsh() {
 | 
			
		||||
cat <<'EOF'
 | 
			
		||||
sdn-navigate () {
 | 
			
		||||
  # optionally: zle zle-line-finish
 | 
			
		||||
  while eval "`SDN=1 sdn "$BUFFER" "$CURSOR"`"
 | 
			
		||||
  do
 | 
			
		||||
    [ -z "$cd" ] || cd "$cd"
 | 
			
		||||
    [ -z "$insert" ] || LBUFFER="$LBUFFER$insert "
 | 
			
		||||
    [ -z "$helper" ] && break
 | 
			
		||||
 | 
			
		||||
    # Workaround for "zsh: suspended (tty output)" when invoking
 | 
			
		||||
    # helpers after the terminal has been resized while running sdn
 | 
			
		||||
    command true
 | 
			
		||||
 | 
			
		||||
    # Add to history, see https://www.zsh.org/mla/workers/2020/msg00633.html
 | 
			
		||||
    fc -R =(print -- "$helper")
 | 
			
		||||
 | 
			
		||||
    /bin/sh -c "$helper" </dev/tty || break
 | 
			
		||||
  done
 | 
			
		||||
  # optionally: zle zle-line-init
 | 
			
		||||
  zle reset-prompt
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
zle -N sdn-navigate
 | 
			
		||||
bindkey '\eo' sdn-navigate
 | 
			
		||||
EOF
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bash() {
 | 
			
		||||
cat <<'EOF'
 | 
			
		||||
# We can't make the shell update the prompt on directory changes
 | 
			
		||||
# since there's no way to invoke `prompt_again()` from a `bind -x`
 | 
			
		||||
# handler but we can work around it by submitting a blank line.
 | 
			
		||||
sdn-cursor () {
 | 
			
		||||
  if [[ $BASH_VERSINFO -lt 5 ]]
 | 
			
		||||
  then echo -n "$SDN_L" | wc -m
 | 
			
		||||
  else echo "$SDN_P"
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sdn-navigate () {
 | 
			
		||||
  SDN_L=$READLINE_LINE SDN_P=$READLINE_POINT
 | 
			
		||||
  READLINE_LINE=
 | 
			
		||||
 | 
			
		||||
  while eval "`SDN=1 sdn "$SDN_L" "$(sdn-cursor)"`"
 | 
			
		||||
  do
 | 
			
		||||
    [[ -z $cd ]] || cd "$cd"
 | 
			
		||||
    [[ -z $insert ]] || {
 | 
			
		||||
      SDN_L="${SDN_L:0:$SDN_P}$insert ${SDN_L:$SDN_P}"
 | 
			
		||||
      ((SDN_P=SDN_P+${#insert}+1))
 | 
			
		||||
    }
 | 
			
		||||
    [[ -z $helper ]] && break
 | 
			
		||||
    history -s -- "$helper"
 | 
			
		||||
    /bin/sh -c "$helper" || break
 | 
			
		||||
  done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sdn-restore () {
 | 
			
		||||
  READLINE_LINE=$SDN_L READLINE_POINT=$SDN_P
 | 
			
		||||
  unset SDN_L SDN_P
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# These never occur in UTF-8: \300-\301 \365-\367 \370-\377
 | 
			
		||||
bind -x '"\300": sdn-navigate'
 | 
			
		||||
bind -x '"\301": sdn-restore'
 | 
			
		||||
bind '"\eo": "\300\C-m\301"'
 | 
			
		||||
EOF
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fish() {
 | 
			
		||||
cat <<'EOF'
 | 
			
		||||
function sdn-navigate
 | 
			
		||||
  set --local IFS
 | 
			
		||||
  set --local buffer (commandline)
 | 
			
		||||
  set --local cursor (commandline --cursor)
 | 
			
		||||
  while eval (SDN=1 sdn $buffer $cursor | \
 | 
			
		||||
    string replace -ar '^(.*?)=' 'set --$1 ')
 | 
			
		||||
    test -z "$cd" || cd "$cd"
 | 
			
		||||
    test -z "$insert" || commandline --insert "$insert "
 | 
			
		||||
    test -z "$helper" && break
 | 
			
		||||
    /bin/sh -c "$helper" || break
 | 
			
		||||
  end
 | 
			
		||||
  commandline --function repaint
 | 
			
		||||
end
 | 
			
		||||
bind \eo sdn-navigate
 | 
			
		||||
EOF
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
elvish() {
 | 
			
		||||
cat <<'EOF'
 | 
			
		||||
edit:insert:binding[Alt-o] = {
 | 
			
		||||
  use str
 | 
			
		||||
  local:reesc = [posix]{ str:replace "'\\''"  "''" $posix }
 | 
			
		||||
  local:posix = [cmd]{ /bin/sh -c $cmd </dev/tty >/dev/tty 2>&1 }
 | 
			
		||||
 | 
			
		||||
  # XXX: the -dot is not a stable API, and may hence break soon
 | 
			
		||||
  # https://elv.sh/ref/builtin.html#do-not-use-functions-and-variables
 | 
			
		||||
  local:buffer = $edit:current-command
 | 
			
		||||
  local:cursor = (str:to-codepoints $buffer[0..$edit:-dot] | count)
 | 
			
		||||
  local:ns = (ns [&])
 | 
			
		||||
  while ?(eval ($reesc (E:SDN=1 sdn $buffer $cursor |
 | 
			
		||||
    sed 's/^local //' | slurp)) &ns=$ns) {
 | 
			
		||||
    if (not-eq $ns[cd] "") { cd $ns[cd] }
 | 
			
		||||
    if (not-eq $ns[insert] "") { edit:insert-at-dot $ns[insert]" " }
 | 
			
		||||
    if (or (eq $ns[helper] "") (not ?($posix $ns[helper]))) { break }
 | 
			
		||||
  }
 | 
			
		||||
  edit:redraw &full=$true
 | 
			
		||||
}
 | 
			
		||||
EOF
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
shell= path=
 | 
			
		||||
while getopts s:f:h opt
 | 
			
		||||
do
 | 
			
		||||
  case $opt in
 | 
			
		||||
  s) shell=$OPTARG;;
 | 
			
		||||
  f) path=$OPTARG;;
 | 
			
		||||
  *) echo "Usage: $0 [-s SHELL] [-f RCPATH | -]"; exit 2
 | 
			
		||||
  esac
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# Figure out the shell to integrate with
 | 
			
		||||
login=$(basename "$SHELL")
 | 
			
		||||
actual=$(ps -p $$ -o ppid= | xargs ps -o comm= -p | sed 's/^-//')
 | 
			
		||||
if [ -z "$shell" ]
 | 
			
		||||
then
 | 
			
		||||
  if [ "$login" != "$actual" ]
 | 
			
		||||
  then
 | 
			
		||||
    echo "Conflict between login ($login) and invoking ($actual) shell."
 | 
			
		||||
    echo "Specify the shell with the -s option."
 | 
			
		||||
    exit 1
 | 
			
		||||
  fi
 | 
			
		||||
  shell=$actual
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Figure out the default initialisation file
 | 
			
		||||
case "$shell" in
 | 
			
		||||
zsh|bash)
 | 
			
		||||
  rc=~/.${shell}rc;;
 | 
			
		||||
fish)
 | 
			
		||||
  rc=${XDG_CONFIG_HOME:-$HOME/.config}/fish/conf.d/sdn.fish;;
 | 
			
		||||
elvish)
 | 
			
		||||
  rc=~/.elvish/rc.elv;;
 | 
			
		||||
*)
 | 
			
		||||
  echo "$shell is not supported."
 | 
			
		||||
  exit 1
 | 
			
		||||
esac
 | 
			
		||||
 | 
			
		||||
# Just print out the snippet if requested
 | 
			
		||||
if [ "$path" = "-" ]
 | 
			
		||||
then
 | 
			
		||||
  $shell
 | 
			
		||||
  exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Finally append to or update the appropriate file
 | 
			
		||||
b="# sdn-install begin"
 | 
			
		||||
e="# sdn-install end"
 | 
			
		||||
[ -z "$path" ] && path=$rc
 | 
			
		||||
mkdir -p "$(dirname "$path")"
 | 
			
		||||
touch "$path"
 | 
			
		||||
 | 
			
		||||
if ! grep -q "^$b" "$path" 2>/dev/null || ! grep -q "^$e" "$path" 2>/dev/null
 | 
			
		||||
then
 | 
			
		||||
  printf "\n$b\n%s\n$e\n" "$($shell)" >> "$path"
 | 
			
		||||
  echo "The snippet has been added to $path"
 | 
			
		||||
  exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# POSIX-compliant in-place sed, trying to retain permissions here
 | 
			
		||||
temp=$path.sdn.new
 | 
			
		||||
cp -p -- "$path" "$temp"
 | 
			
		||||
sed < "$path" > "$temp" "/^$b/,/^$e/c\\
 | 
			
		||||
$b\\
 | 
			
		||||
$($shell | sed 's/\\/&&/g; s/$/\\/')
 | 
			
		||||
$e"
 | 
			
		||||
mv -- "$temp" "$path"
 | 
			
		||||
echo "The snippet in $path has been updated."
 | 
			
		||||
							
								
								
									
										35
									
								
								sdn-install.1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								sdn-install.1
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
.Dd October 27, 2020
 | 
			
		||||
.Dt SDN-INSTALL 1
 | 
			
		||||
.Os
 | 
			
		||||
.Sh NAME
 | 
			
		||||
.Nm sdn-install
 | 
			
		||||
.Nd integrate sdn with the shell
 | 
			
		||||
.Sh SYNOPSIS
 | 
			
		||||
.Nm sdn-install
 | 
			
		||||
.Op Fl s Ar shell
 | 
			
		||||
.Op Fl p Ar - | rcpath
 | 
			
		||||
.Sh DESCRIPTION
 | 
			
		||||
.Nm
 | 
			
		||||
integrates
 | 
			
		||||
.Xr sdn 1
 | 
			
		||||
with your shell, binding it to M-o.  If the navigator has already been
 | 
			
		||||
integrated, it updates the snippet in-place.
 | 
			
		||||
.Pp
 | 
			
		||||
The options are as follows:
 | 
			
		||||
.Bl -tag -width Ds
 | 
			
		||||
.It Fl p Ar -
 | 
			
		||||
Merely print the integration snippet for the appropriate shell to the standard
 | 
			
		||||
output, not changing anything.
 | 
			
		||||
.It Fl p Ar rcpath
 | 
			
		||||
Install the integration snippet into a different shell initialization file than
 | 
			
		||||
the default one for your user.
 | 
			
		||||
.It Fl s Ar shell
 | 
			
		||||
If you want to integrate
 | 
			
		||||
.Xr sdn 1
 | 
			
		||||
with a different shell than the one you're running, use this option to specify
 | 
			
		||||
it.
 | 
			
		||||
.El
 | 
			
		||||
.Sh REPORTING BUGS
 | 
			
		||||
Use
 | 
			
		||||
.Lk https://git.janouch.name/p/sdn
 | 
			
		||||
to report bugs, request features, or submit pull requests.
 | 
			
		||||
							
								
								
									
										222
									
								
								sdn-mc-ext.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								sdn-mc-ext.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,222 @@
 | 
			
		||||
//
 | 
			
		||||
// sdn-mc-ext: Midnight Commander extension file processor
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2024, Přemysl Eric Janouch <p@janouch.name>
 | 
			
		||||
//
 | 
			
		||||
// Permission to use, copy, modify, and/or distribute this software for any
 | 
			
		||||
// purpose with or without fee is hereby granted.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 | 
			
		||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 | 
			
		||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 | 
			
		||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 | 
			
		||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 | 
			
		||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 | 
			
		||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
#include <cctype>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <regex>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
// Trailing return types make C++ syntax suck considerably less
 | 
			
		||||
#define fun static auto
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
// It is completely fine if this only modifies ASCII letters.
 | 
			
		||||
fun tolower (const string &s) -> string {
 | 
			
		||||
    string result;
 | 
			
		||||
	for (auto c : s) result += tolower (c);
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun shell_escape (const string &v) -> string {
 | 
			
		||||
    return "'" + regex_replace (v, regex {"'"}, "'\\''") + "'";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
string arg_type, arg_path, arg_basename, arg_dirname, arg_verb;
 | 
			
		||||
unordered_map<string, unordered_map<string, string>> sections;
 | 
			
		||||
 | 
			
		||||
fun expand_command (string command) -> pair<string, string> {
 | 
			
		||||
	regex re_sequence {R"(%(%|[[:alpha:]]*\{([^}]*)\}|[[:alpha:]]+))"};
 | 
			
		||||
	regex re_name {R"([^{}]*)"};
 | 
			
		||||
	regex re_parameter {R"([^,]+")"};
 | 
			
		||||
	string kind, out, pipe; smatch m;
 | 
			
		||||
	while (regex_search (command, m, re_sequence)) {
 | 
			
		||||
		out.append (m.prefix ());
 | 
			
		||||
		auto seq = m.str (1);
 | 
			
		||||
		command = m.suffix ();
 | 
			
		||||
 | 
			
		||||
		string argument = m.str (2);
 | 
			
		||||
		if (regex_search (seq, m, re_name))
 | 
			
		||||
			seq = m.str ();
 | 
			
		||||
 | 
			
		||||
		if (seq == "%") {
 | 
			
		||||
			out += "%";
 | 
			
		||||
		} else if (seq == "p") {
 | 
			
		||||
			out += shell_escape (arg_basename);
 | 
			
		||||
		} else if (seq == "f") {
 | 
			
		||||
			out += shell_escape (arg_path);
 | 
			
		||||
		} else if (seq == "d") {
 | 
			
		||||
			out += shell_escape (arg_dirname);
 | 
			
		||||
		} else if (seq == "var") {
 | 
			
		||||
			string value;
 | 
			
		||||
			if (auto colon = argument.find (':'); colon == argument.npos) {
 | 
			
		||||
				if (auto v = getenv (argument.c_str ()))
 | 
			
		||||
					value = v;
 | 
			
		||||
			} else {
 | 
			
		||||
				value = argument.substr (colon + 1);
 | 
			
		||||
				if (auto v = getenv (argument.substr (0, colon).c_str ()))
 | 
			
		||||
					value = v;
 | 
			
		||||
			}
 | 
			
		||||
			out += shell_escape (value);
 | 
			
		||||
		} else if (seq == "cd") {
 | 
			
		||||
			kind = seq;
 | 
			
		||||
			command = regex_replace (command, regex {"^ +"}, "");
 | 
			
		||||
		} else if (seq == "view") {
 | 
			
		||||
			kind = seq;
 | 
			
		||||
			command = regex_replace (command, regex {"^ +"}, "");
 | 
			
		||||
 | 
			
		||||
			sregex_token_iterator it (argument.begin (), argument.end (),
 | 
			
		||||
				re_parameter, 0), end;
 | 
			
		||||
			for (; it != end; it++) {
 | 
			
		||||
				if (*it == "hex")
 | 
			
		||||
					pipe.append (" | od -t x1");
 | 
			
		||||
 | 
			
		||||
				// more(1) and less(1) either ignore or display this:
 | 
			
		||||
				//if (*it == "nroff")
 | 
			
		||||
				//	pipe.append (" | col -b");
 | 
			
		||||
			}
 | 
			
		||||
		} else if (seq == "") {
 | 
			
		||||
			cerr << "sdn-mc-ext: prompting not supported" << endl;
 | 
			
		||||
			return {};
 | 
			
		||||
		} else {
 | 
			
		||||
			cerr << "sdn-mc-ext: unsupported: %" << seq << endl;
 | 
			
		||||
			return {};
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return {kind,
 | 
			
		||||
		pipe.empty () ? out.append (command) : "(" + out + ")" + pipe};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun print_command (string cmd) {
 | 
			
		||||
	auto command = expand_command (cmd);
 | 
			
		||||
	cout << get<0> (command) << endl << get<1> (command) << endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun section_matches (const unordered_map<string, string> §ion) -> bool {
 | 
			
		||||
	if (section.count ("Directory"))
 | 
			
		||||
		return false;
 | 
			
		||||
 | 
			
		||||
	// The configuration went through some funky changes;
 | 
			
		||||
	// unescape \\ but leave other escapes alone.
 | 
			
		||||
	auto filter_re = [](const string &s) {
 | 
			
		||||
		string result;
 | 
			
		||||
		for (size_t i = 0; i < s.length (); ) {
 | 
			
		||||
			auto c = s[i++];
 | 
			
		||||
			if (c == '\\' && i < s.length ())
 | 
			
		||||
				if (c = s[i++]; c != '\\')
 | 
			
		||||
					result += '\\';
 | 
			
		||||
			result += c;
 | 
			
		||||
		}
 | 
			
		||||
		return result;
 | 
			
		||||
	};
 | 
			
		||||
	auto is_true = [&](const string &name) {
 | 
			
		||||
		auto value = section.find (name);
 | 
			
		||||
		return value != section.end () && value->second == "true";
 | 
			
		||||
	};
 | 
			
		||||
	if (auto kv = section.find ("Type"); kv != section.end ()) {
 | 
			
		||||
		auto flags = std::regex::ECMAScript;
 | 
			
		||||
		if (is_true ("TypeIgnoreCase"))
 | 
			
		||||
			flags |= regex_constants::icase;
 | 
			
		||||
		if (!regex_search (arg_type, regex {filter_re (kv->second), flags}))
 | 
			
		||||
			return false;
 | 
			
		||||
	}
 | 
			
		||||
	auto basename = arg_basename;
 | 
			
		||||
	if (auto kv = section.find ("Regex"); kv != section.end ()) {
 | 
			
		||||
		auto flags = std::regex::ECMAScript;
 | 
			
		||||
		if (is_true ("RegexIgnoreCase"))
 | 
			
		||||
			flags |= regex_constants::icase;
 | 
			
		||||
		return regex_search (basename, regex {filter_re (kv->second), flags});
 | 
			
		||||
	}
 | 
			
		||||
	if (auto kv = section.find ("Shell"); kv != section.end ()) {
 | 
			
		||||
		auto value = kv->second;
 | 
			
		||||
		if (is_true ("ShellIgnoreCase")) {
 | 
			
		||||
			value = tolower (value);
 | 
			
		||||
			basename = tolower (arg_basename);
 | 
			
		||||
		}
 | 
			
		||||
		if (value.empty () || value[0] != '.')
 | 
			
		||||
			return value == basename;
 | 
			
		||||
		return basename.length () >= value.length () &&
 | 
			
		||||
			basename.substr (basename.length () - value.length ()) == value;
 | 
			
		||||
	}
 | 
			
		||||
	return !arg_type.empty ();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun process (const string §ion) -> bool {
 | 
			
		||||
	auto full = sections.at (section);
 | 
			
		||||
	if (auto include = full.find ("Include"); include != full.end ()) {
 | 
			
		||||
		full.erase ("Open");
 | 
			
		||||
		full.erase ("View");
 | 
			
		||||
		full.erase ("Edit");
 | 
			
		||||
 | 
			
		||||
		if (auto included = sections.find ("Include/" + include->second);
 | 
			
		||||
			included != sections.end ()) {
 | 
			
		||||
			for (const auto &kv : included->second)
 | 
			
		||||
				full[kv.first] = kv.second;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (getenv ("SDN_MC_EXT_DEBUG")) {
 | 
			
		||||
		cerr << "[" << section << "]" << endl;
 | 
			
		||||
		for (const auto &kv : full)
 | 
			
		||||
			cerr << "  " << kv.first << ": " << kv.second << endl;
 | 
			
		||||
	}
 | 
			
		||||
	if (full.count (arg_verb) && section_matches (full)) {
 | 
			
		||||
		print_command (full[arg_verb]);
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main (int argc, char *argv[]) {
 | 
			
		||||
	if (argc != 6) {
 | 
			
		||||
		cerr << "Usage: " << argv[0]
 | 
			
		||||
			<< " TYPE PATH BASENAME DIRNAME VERB < mc.ext.ini" << endl;
 | 
			
		||||
		return 2;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	arg_type = argv[1];
 | 
			
		||||
	arg_path = argv[2], arg_basename = argv[3], arg_dirname = argv[4];
 | 
			
		||||
	arg_verb = argv[5];
 | 
			
		||||
 | 
			
		||||
	string line, section;
 | 
			
		||||
	vector<string> order;
 | 
			
		||||
	regex re_entry {R"(^([-\w]+) *= *(.*)$)"};
 | 
			
		||||
	smatch m;
 | 
			
		||||
	while (getline (cin, line)) {
 | 
			
		||||
		if (line.empty () || line[0] == '#') {
 | 
			
		||||
			continue;
 | 
			
		||||
		} else if (auto length = line.length();
 | 
			
		||||
			line.find_last_of ('[') == 0 &&
 | 
			
		||||
			line.find_first_of (']') == length - 1) {
 | 
			
		||||
			order.push_back ((section = line.substr (1, length - 2)));
 | 
			
		||||
		} else if (regex_match (line, m, re_entry)) {
 | 
			
		||||
			sections[section][m[1]] = m[2];
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	for (const auto §ion : order) {
 | 
			
		||||
		if (section == "mc.ext.ini" ||
 | 
			
		||||
			section == "Default" ||
 | 
			
		||||
			section.substr (0, 8) == "Include/")
 | 
			
		||||
			continue;
 | 
			
		||||
		if (process (section))
 | 
			
		||||
			return 0;
 | 
			
		||||
	}
 | 
			
		||||
	print_command (sections["Default"][arg_verb]);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										54
									
								
								sdn-view
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										54
									
								
								sdn-view
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
#!/bin/sh -e
 | 
			
		||||
# sdn-view: a viewer for sdn that makes use of Midnight Commander configuration
 | 
			
		||||
# to make more kinds of files directly viewable
 | 
			
		||||
 | 
			
		||||
if [ "$#" -ne 1 ]
 | 
			
		||||
then
 | 
			
		||||
	echo "Usage: $0 FILE" >&2
 | 
			
		||||
	exit 2
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# This handles both MC_DATADIR and odd installation locations.
 | 
			
		||||
datadir=
 | 
			
		||||
if command -v mc >/dev/null
 | 
			
		||||
then datadir=$(mc --datadir | sed 's/ (.*)$//')
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
config=
 | 
			
		||||
for dir in "$HOME"/.config/mc "$datadir" /etc/mc
 | 
			
		||||
do
 | 
			
		||||
	if [ -n "$dir" -a -f "$dir/mc.ext.ini" ]
 | 
			
		||||
	then
 | 
			
		||||
		config=$dir/mc.ext.ini
 | 
			
		||||
		break
 | 
			
		||||
	fi
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# This is often used in %env{} expansion, so let's be on the same page.
 | 
			
		||||
export PAGER=${PAGER:-less}
 | 
			
		||||
 | 
			
		||||
export MC_EXT_FILENAME=$(realpath "$1")
 | 
			
		||||
export MC_EXT_BASENAME=$(basename "$1")
 | 
			
		||||
export MC_EXT_CURRENTDIR=$(dirname "$MC_EXT_FILENAME")
 | 
			
		||||
output=$(sdn-mc-ext <"$config" "$(file -Lbz "$1")" \
 | 
			
		||||
	"$MC_EXT_FILENAME" "$MC_EXT_BASENAME" "$MC_EXT_CURRENTDIR" View || :)
 | 
			
		||||
kind=$(echo "$output" | sed -n 1p)
 | 
			
		||||
command=$(echo "$output" | sed -n 2p)
 | 
			
		||||
 | 
			
		||||
case "$kind" in
 | 
			
		||||
view)
 | 
			
		||||
	if [ -n "$command" ]
 | 
			
		||||
	then eval "$command" | "$PAGER"
 | 
			
		||||
	else "$PAGER" -- "$MC_EXT_FILENAME"
 | 
			
		||||
	fi
 | 
			
		||||
	;;
 | 
			
		||||
'')
 | 
			
		||||
	if [ -n "$command" ]
 | 
			
		||||
	then eval "$command"
 | 
			
		||||
	else "$PAGER" -- "$MC_EXT_FILENAME"
 | 
			
		||||
	fi
 | 
			
		||||
	;;
 | 
			
		||||
*)
 | 
			
		||||
	echo "Unsupported: $kind" >&2
 | 
			
		||||
	exit 1
 | 
			
		||||
esac
 | 
			
		||||
							
								
								
									
										24
									
								
								sdn-view.1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								sdn-view.1
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
.Dd December 30, 2024
 | 
			
		||||
.Dt SDN-VIEW 1
 | 
			
		||||
.Os
 | 
			
		||||
.Sh NAME
 | 
			
		||||
.Nm sdn-view
 | 
			
		||||
.Nd run Midnight Commander view configuration externally
 | 
			
		||||
.Sh SYNOPSIS
 | 
			
		||||
.Nm sdn-view
 | 
			
		||||
.Ar path
 | 
			
		||||
.Sh DESCRIPTION
 | 
			
		||||
.Nm
 | 
			
		||||
invokes
 | 
			
		||||
.Ev PAGER
 | 
			
		||||
or a fallback pager on the passed filename.
 | 
			
		||||
.Pp
 | 
			
		||||
If it succeeds in finding a
 | 
			
		||||
.Xr mc 1
 | 
			
		||||
.Pa mc.ext.ini
 | 
			
		||||
file, it will first process it, and apply any matching filter,
 | 
			
		||||
or run the respective command.
 | 
			
		||||
.Sh REPORTING BUGS
 | 
			
		||||
Use
 | 
			
		||||
.Lk https://git.janouch.name/p/sdn
 | 
			
		||||
to report bugs, request features, or submit pull requests.
 | 
			
		||||
							
								
								
									
										132
									
								
								sdn.1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								sdn.1
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,132 @@
 | 
			
		||||
\" https://mandoc.bsd.lv/man/roff.7.html#Sentence_Spacing
 | 
			
		||||
.Dd December 30, 2024
 | 
			
		||||
.Dt SDN 1
 | 
			
		||||
.Os
 | 
			
		||||
.Sh NAME
 | 
			
		||||
.Nm sdn
 | 
			
		||||
.Nd directory navigator
 | 
			
		||||
.Sh SYNOPSIS
 | 
			
		||||
.Nm sdn
 | 
			
		||||
.Op Ar line Ar point
 | 
			
		||||
.Nm sdn
 | 
			
		||||
.Cm --version
 | 
			
		||||
.Sh DESCRIPTION
 | 
			
		||||
.Nm
 | 
			
		||||
is a simple directory navigator that you can launch while editing shell
 | 
			
		||||
commands.
 | 
			
		||||
Use the
 | 
			
		||||
.Xr sdn-install 1
 | 
			
		||||
script to integrate it with your shell, then invoke it at any time with M-o.
 | 
			
		||||
.Pp
 | 
			
		||||
Press F1 to get a list of active key bindings and their assigned actions,
 | 
			
		||||
grouped by their contexts.
 | 
			
		||||
.Pp
 | 
			
		||||
Program arguments are only used by integration snippets to forward the parent
 | 
			
		||||
shell's command line.
 | 
			
		||||
The
 | 
			
		||||
.Ar point
 | 
			
		||||
is given in terms of characters.
 | 
			
		||||
.Sh OPTIONS
 | 
			
		||||
While some behaviour can be toggled from within the program, some can only be
 | 
			
		||||
changed by modifying configuration files manually.
 | 
			
		||||
.Pp
 | 
			
		||||
The files follow a simple syntax derived from the Bourne shell: each option is
 | 
			
		||||
on its own line, with words separated by linear whitespace.
 | 
			
		||||
Comments start with a hash (#) and continue until the end of the line.
 | 
			
		||||
All special characters may be quoted using either a backslash or single-quoted
 | 
			
		||||
strings.
 | 
			
		||||
.Pp
 | 
			
		||||
The options and the default key bindings controlling them are as follows:
 | 
			
		||||
.Bl -tag
 | 
			
		||||
.It full-view Em bool No (t)
 | 
			
		||||
If non-zero, the equivalent format to
 | 
			
		||||
.Ql ls -l
 | 
			
		||||
is used to display directory contents rather than simply listing the filenames.
 | 
			
		||||
.It gravity Em bool
 | 
			
		||||
If non-zero, all entries stick to the bottom of the screen, i.e., all empty
 | 
			
		||||
space is at the top.
 | 
			
		||||
.It reverse-sort Em bool No (R)
 | 
			
		||||
If non-zero, the order of entries is reversed.
 | 
			
		||||
.It show-hidden Em bool No (M-.)
 | 
			
		||||
If non-zero, filenames beginning with a full stop are shown.
 | 
			
		||||
.It ext-helpers Em bool
 | 
			
		||||
If non-zero, viewers and editors are launched from the parent shell.
 | 
			
		||||
This way you can suspend them and use job control features of the shell.
 | 
			
		||||
However it also enforces any pending change to the shell's working directory.
 | 
			
		||||
.It sort-column Em number No (< >)
 | 
			
		||||
The zero-based index of the
 | 
			
		||||
.Ql full-view
 | 
			
		||||
column that entries are ordered by.
 | 
			
		||||
.El
 | 
			
		||||
.Sh ENVIRONMENT
 | 
			
		||||
.Bl -tag -width 15n
 | 
			
		||||
.It Ev LS_COLORS
 | 
			
		||||
Used to retrieve filename colours.
 | 
			
		||||
The format is described in
 | 
			
		||||
.Xr dir_colors 5
 | 
			
		||||
and you can use the
 | 
			
		||||
.Xr dircolors 1
 | 
			
		||||
utility to initialize this variable.
 | 
			
		||||
.It Ev PAGER
 | 
			
		||||
The viewer program to be launched by the F3 and F13 key bindings as well as
 | 
			
		||||
to show the internal help message.
 | 
			
		||||
If none is set, it defaults to
 | 
			
		||||
.Xr less 1 .
 | 
			
		||||
.It Ev VISUAL , Ev EDITOR
 | 
			
		||||
The editor program to be launched by the F4 key binding.
 | 
			
		||||
If neither variable is set, it defaults to
 | 
			
		||||
.Xr vi 1 .
 | 
			
		||||
.El
 | 
			
		||||
.Sh FILES
 | 
			
		||||
.Bl -tag -width 25n -compact
 | 
			
		||||
.It Pa ~/.config/sdn/config
 | 
			
		||||
Program configuration and navigation state, initialized or overwritten on exit.
 | 
			
		||||
.It Pa ~/.config/sdn/bindings
 | 
			
		||||
Custom key binding overrides.
 | 
			
		||||
.It Pa ~/.config/sdn/look
 | 
			
		||||
Redefine terminal attributes for UI elements.
 | 
			
		||||
.El
 | 
			
		||||
.Sh EXAMPLES
 | 
			
		||||
.Ss Pa bindings
 | 
			
		||||
Key names or combinations follow the Emacs syntax for Control and Meta prefixes
 | 
			
		||||
and
 | 
			
		||||
.Xr terminfo 5
 | 
			
		||||
names are used for special keys.
 | 
			
		||||
To obtain more vifm-like controls and Windows-like quit abilities:
 | 
			
		||||
.Bd -literal -offset indent
 | 
			
		||||
normal h parent
 | 
			
		||||
normal l enter
 | 
			
		||||
normal M-f4 quit
 | 
			
		||||
.Ed
 | 
			
		||||
.Pp
 | 
			
		||||
Midnight Commander binds the same traversal actions to sequences normally
 | 
			
		||||
unknown to ncurses, due to them being missing from terminfo.
 | 
			
		||||
You'll need to define them manually to match your terminal.
 | 
			
		||||
For rxvt, that would be:
 | 
			
		||||
.Bd -literal -offset indent
 | 
			
		||||
define C-ppage ^[[5^
 | 
			
		||||
define C-npage ^[[6^
 | 
			
		||||
normal C-ppage parent
 | 
			
		||||
normal C-npage enter
 | 
			
		||||
.Ed
 | 
			
		||||
.Pp
 | 
			
		||||
Escape characters must be inserted verbatim, e.g., by pressing C-v ESC in vi,
 | 
			
		||||
or C-q ESC in Emacs.
 | 
			
		||||
.Ss Pa look
 | 
			
		||||
Terminal attributes are accepted in a format similar to that of
 | 
			
		||||
.Xr git-config 1 ,
 | 
			
		||||
only named colours aren't supported.
 | 
			
		||||
For a black-on-white terminal supporting 256 colours, a theme such as the
 | 
			
		||||
following may work:
 | 
			
		||||
.Bd -literal -offset indent
 | 
			
		||||
cursor 231 202
 | 
			
		||||
select 202 bold
 | 
			
		||||
bar 16 255 ul
 | 
			
		||||
cwd bold
 | 
			
		||||
input
 | 
			
		||||
cmdline 145
 | 
			
		||||
.Ed
 | 
			
		||||
.Sh REPORTING BUGS
 | 
			
		||||
Use
 | 
			
		||||
.Lk https://git.janouch.name/p/sdn
 | 
			
		||||
to report bugs, request features, or submit pull requests.
 | 
			
		||||
		Reference in New Issue
	
	Block a user