Compare commits

...
17 Commits
Author SHA1 Message Date
root b91789df39 renamed type_definitions.h to main.h 2026-11-10 11:27:27 +01:00
root f2e3801b8a moved _XOPEN_SOURCE=700 to makefile 2026-11-10 11:23:09 +01:00
root 71f2709da4 readme update 2026-11-01 12:28:55 +01:00
root 3ad341e3c9 readme comparison cleanup 2026-10-27 09:09:51 +01:00
root 8772d10c4c implemented style for pdfs 2026-10-21 20:28:33 +02:00
root 46bf3c23c3 cleaned up notes in readme 2026-10-18 21:59:27 +02:00
root 4d21f9e67d do not enter '.git' by default in tree mode 2026-10-18 21:44:04 +02:00
root e5746c38bb added completion function for bash 2026-10-14 13:05:44 +02:00
root 6f28e63e3a feature to print all arguments for completions 2026-10-14 13:05:03 +02:00
root 079ccd4ed3 added latex and assembly files to sources 2026-10-13 23:10:48 +02:00
root dfd525bed2 default style for files 2026-10-13 16:25:23 +02:00
root 95fc4dec6a implemented style for executables 2026-10-12 18:45:37 +02:00
root 7a78bc6fc8 bold & underlined for makefiles 2026-10-11 14:57:25 +02:00
root 9b662f17bb fixed sorting by extension 2026-10-11 14:57:05 +02:00
root 62515e8a1b show '-' for entries without size 2026-10-10 17:25:36 +02:00
root 364ce8ea67 added cmakelists file to makefile category 2026-10-10 14:15:33 +02:00
root e536442616 fixed extra newline after output 2026-10-09 21:52:56 +02:00
12 changed files with 138 additions and 49 deletions

No files matched your search

+1 -1
View File
@@ -32,7 +32,7 @@ WCC := -Wconversion \
DEBUG_FLAGS := -O0 -g3 DEBUG_FLAGS := -O0 -g3
C_DEF := C_DEF := _XOPEN_SOURCE=700
C_SRC := main.c \ C_SRC := main.c \
log.c \ log.c \
+2 -1
View File
@@ -36,13 +36,14 @@ typedef struct {
bool show_all; bool show_all;
bool show_almost_all; bool show_almost_all;
bool case_sensitive_sorting; bool case_sensitive_sorting;
size_t depth;
bool no_colour; bool no_colour;
bool group_directories; bool group_directories;
bool display_help; bool display_help;
bool long_view; bool long_view;
bool reverse_order; bool reverse_order;
bool tree_view; bool tree_view;
bool show_git_dir;
size_t depth;
permission_mode_t permission_mode; permission_mode_t permission_mode;
sorting_mode_t sorting_mode; sorting_mode_t sorting_mode;
time_mode_t time_mode; time_mode_t time_mode;
+15 -7
View File
@@ -55,20 +55,28 @@ const style_t socket_style[ SOCK_STYLE_NUM ] = { style_none };
const uint32_t socket_colour = 0xEEEEEE; const uint32_t socket_colour = 0xEEEEEE;
#define EXEC_STYLE_NUM ( ( int )1 ) #define EXEC_STYLE_NUM ( ( int )1 )
const style_t exec_style[ EXEC_STYLE_NUM ] = { style_none }; const style_t executable_style[ EXEC_STYLE_NUM ] = { style_bold };
const uint32_t exec_colour = 0xEEEEEE; const uint32_t executable_colour = 0x34AD1F;
// files by extension // files by extension
#define MAKE_STYLE_NUM ( ( int )1 ) #define MAKE_STYLE_NUM ( ( int )2 )
const style_t makefile_style[ MAKE_STYLE_NUM ] = { style_none }; const style_t makefile_style[ MAKE_STYLE_NUM ] = { style_bold, style_underlined };
const uint32_t makefile_colour = 0xEAE977; const uint32_t makefile_colour = 0xEAE977;
#define SRC_STYLE_NUM ( ( int )1 ) #define SRC_STYLE_NUM ( ( int )1 )
const style_t source_style[ SRC_STYLE_NUM ] = { style_none }; const style_t source_style[ SRC_STYLE_NUM ] = { style_bold };
const uint32_t source_colour = 0x6FADD8; const uint32_t source_colour = 0x6FADD8;
#define AR_STYLE_NUM ( ( int )1 ) #define AR_STYLE_NUM ( ( int )1 )
const style_t archive_style[ AR_STYLE_NUM ] = { style_none }; const style_t archive_style[ AR_STYLE_NUM ] = { style_bold };
const uint32_t archive_colour = 0xE02482; const uint32_t archive_colour = 0x885ACE;
#define PDF_STYLE_NUM ( ( int )1 )
const style_t pdf_style[ PDF_STYLE_NUM ] = { style_none };
const uint32_t pdf_colour = 0x4D70E9;
#define REG_STYLE_NUM ( ( int )1 )
const style_t regular_style[ REG_STYLE_NUM ] = { style_none };
const uint32_t regular_colour = 0xFFFFFF;
#endif #endif
+1 -1
View File
@@ -2,7 +2,7 @@
#define __DISPLAY_H #define __DISPLAY_H
#include <stdbool.h> #include <stdbool.h>
#include "type_definitions.h" #include "main.h"
#include "arguments.h" #include "arguments.h"
void display_type( entry_type_t type, bool no_colour ); void display_type( entry_type_t type, bool no_colour );
+2 -6
View File
@@ -1,9 +1,5 @@
#ifndef __TYPE_DEFINITIONS_H #ifndef __MAIN_H
#define __TYPE_DEFINITIONS_H #define __MAIN_H
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 700
#endif
#include <linux/limits.h> #include <linux/limits.h>
#include <sys/stat.h> #include <sys/stat.h>
+1 -1
View File
@@ -2,7 +2,7 @@
#define __SORTING_H #define __SORTING_H
#include <stdbool.h> #include <stdbool.h>
#include "type_definitions.h" #include "main.h"
#include "arguments.h" #include "arguments.h"
int sort_entries( int sort_entries(
+4 -2
View File
@@ -1,4 +1,6 @@
# `scan` # `scan`
This is a replacement for `ls` with additional features. `scan` is a combination of `ls` and `tree`, with colouring by
Though it may result as a rewrite of `eza` (formerly `exa`). filetype.
I wrote this as a fun side project and to replace `eza`
(formerly `exa`) on my setup.
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
if ! $(command -v scan &>/dev/null); then
exit 1
fi
function _scan {
CURRENT_WORD=${COMP_WORDS[COMP_CWORD]}
if [ "${CURRENT_WORD:0:1}" == "-" ]; then
OPTIONS="$(scan --completions)"
COMPREPLY=($(compgen -W "${OPTIONS}" -- $CURRENT_WORD))
else
COMPREPLY=($(compgen -f))
fi
}
complete -F _scan scan
+41 -1
View File
@@ -14,6 +14,7 @@
#define KEY_CASE_SENSITIVE ( ( int )'c' ) #define KEY_CASE_SENSITIVE ( ( int )'c' )
#define KEY_DEPTH ( ( int )'d' ) #define KEY_DEPTH ( ( int )'d' )
#define KEY_GROUP_DIRECTORIES ( ( int )'g' ) #define KEY_GROUP_DIRECTORIES ( ( int )'g' )
#define KEY_SHOW_GIT_DIR ( ( int )'G' )
#define KEY_HELP ( ( int )'h' ) #define KEY_HELP ( ( int )'h' )
#define KEY_LONG_VIEW ( ( int )'l' ) #define KEY_LONG_VIEW ( ( int )'l' )
#define KEY_PERMISSIONS ( ( int )'p' ) #define KEY_PERMISSIONS ( ( int )'p' )
@@ -22,9 +23,11 @@
#define KEY_TREE_VIEW ( ( int )'t' ) #define KEY_TREE_VIEW ( ( int )'t' )
#define KEY_TIME_MODE ( ( int )'T' ) #define KEY_TIME_MODE ( ( int )'T' )
#define KEY_NO_COLOUR ( ( int )0x101 ) #define KEY_NO_COLOUR ( ( int )0x101 )
#define KEY_COMPLETIONS ( ( int )0x102 )
// function prototypes // function prototypes
static error_t arg_parser( int key, char* arg, struct argp_state* state ); static error_t arg_parser( int key, char* arg, struct argp_state* state );
void print_completions( void );
// constant definitions // constant definitions
const char* argp_program_version = "scan version 0.1"; const char* argp_program_version = "scan version 0.1";
@@ -86,7 +89,15 @@ static struct argp_option options[] =
.group = 0 .group = 0
}, },
{ {
.name = NULL, .name = "show-git-directory",
.key = KEY_SHOW_GIT_DIR,
.arg = NULL,
.flags = 0,
.doc = "do not ignore '.git' directory",
.group = 0
},
{
.name = "help",
.key = KEY_HELP, .key = KEY_HELP,
.arg = NULL, .arg = NULL,
.flags = 0, .flags = 0,
@@ -141,6 +152,14 @@ static struct argp_option options[] =
.doc = "time to display for directory entries", .doc = "time to display for directory entries",
.group = 0 .group = 0
}, },
{
.name = "completions",
.key = KEY_COMPLETIONS,
.arg = NULL,
.flags = OPTION_HIDDEN,
.doc = NULL,
.group = 0
},
{ 0 } // this is required to properly end the options array .. { 0 } // this is required to properly end the options array ..
}; };
@@ -165,6 +184,7 @@ void initialise_args( arguments_t* arguments )
arguments->depth = MAX_TREE_DEPTH; arguments->depth = MAX_TREE_DEPTH;
arguments->no_colour = false; arguments->no_colour = false;
arguments->group_directories = false; arguments->group_directories = false;
arguments->show_git_dir = false;
arguments->display_help = false; arguments->display_help = false;
arguments->long_view = false; arguments->long_view = false;
arguments->reverse_order = false; arguments->reverse_order = false;
@@ -227,6 +247,9 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state )
case KEY_GROUP_DIRECTORIES: case KEY_GROUP_DIRECTORIES:
arguments->group_directories = true; arguments->group_directories = true;
break; break;
case KEY_SHOW_GIT_DIR:
arguments->show_git_dir = true;
break;
case KEY_HELP: case KEY_HELP:
arguments->display_help = true; arguments->display_help = true;
break; break;
@@ -309,6 +332,9 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state )
return ARGP_ERR_UNKNOWN; return ARGP_ERR_UNKNOWN;
} }
break; break;
case KEY_COMPLETIONS:
print_completions();
break;
case ARGP_KEY_ARG: case ARGP_KEY_ARG:
if ( 0 == state->arg_num ) if ( 0 == state->arg_num )
arguments->path_count = 0u; arguments->path_count = 0u;
@@ -322,3 +348,17 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state )
return 0; return 0;
} }
void print_completions( void )
{
const struct argp_option* opt = options;
for ( opt = options; opt->name; opt++ )
{
if ( opt->name && !(opt->flags & OPTION_HIDDEN ) )
fprintf( stdout, "--%s\n", opt->name );
if ( 128 > opt->key && !(opt->flags & OPTION_HIDDEN ) )
fprintf( stdout, "-%c\n", opt->key );
}
exit( 0 );
}
+40 -11
View File
@@ -1,12 +1,10 @@
#define _XOPEN_SOURCE 700
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <pwd.h> #include <pwd.h>
#include <time.h> #include <time.h>
#include "display.h" #include "display.h"
#include "type_definitions.h" #include "main.h"
#include "arguments.h" #include "arguments.h"
#include "log.h" #include "log.h"
#include "format.h" #include "format.h"
@@ -20,6 +18,7 @@ void display_permissions( const char* const permissions, bool no_colour );
bool compare_makefile( const directory_entry_t* const entry ); bool compare_makefile( const directory_entry_t* const entry );
bool compare_archives( const directory_entry_t* const entry ); bool compare_archives( const directory_entry_t* const entry );
bool compare_sources( const directory_entry_t* const entry ); bool compare_sources( const directory_entry_t* const entry );
bool compare_pdf( const directory_entry_t* const entry );
static void size_to_string( static void size_to_string(
const directory_entry_t* const entry, const directory_entry_t* const entry,
char* file_size, char* file_size,
@@ -273,8 +272,12 @@ void set_file_style( const directory_entry_t* const entry )
{ {
if ( !entry ) return; if ( !entry ) return;
// makefiles and readmes if ( entry->stats.st_mode & S_IXUSR )
if ( compare_makefile( entry ) ) {
format_set_style( &executable_style[ 0 ], EXEC_STYLE_NUM );
format_set_colour( executable_colour );
}
else if ( compare_makefile( entry ) )
{ {
format_set_style( &makefile_style[ 0 ], MAKE_STYLE_NUM ); format_set_style( &makefile_style[ 0 ], MAKE_STYLE_NUM );
format_set_colour( makefile_colour ); format_set_colour( makefile_colour );
@@ -289,13 +292,31 @@ void set_file_style( const directory_entry_t* const entry )
format_set_style( &source_style[ 0 ], SRC_STYLE_NUM ); format_set_style( &source_style[ 0 ], SRC_STYLE_NUM );
format_set_colour( source_colour ); format_set_colour( source_colour );
} }
else if ( compare_pdf( entry ) )
{
format_set_style( &pdf_style[ 0 ], PDF_STYLE_NUM );
format_set_colour( pdf_colour );
}
else
{
format_set_style( &regular_style[ 0 ], REG_STYLE_NUM );
format_set_colour( regular_colour );
}
} }
bool compare_makefile( const directory_entry_t* const entry ) bool compare_makefile( const directory_entry_t* const entry )
{ {
return 0 == compare_strings( entry->name, "makefile", NAME_MAX, false ) return 0 == compare_strings( entry->name, "makefile", 9, false )
|| 0 == compare_strings( entry->name, "readme", 6, false ) || 0 == compare_strings( entry->name, "readme", 7, false )
|| 0 == compare_strings( entry->extension, "mk", 3, false ); /* do not compare the zero character, in order to also chatch
* readmes with extensions like '.md' or '.txt'.
*
* this also flags nonsensical files like 'readme.bullshit'
* but this is deemed acceptable
*/
|| 0 == compare_strings( entry->name, "readme.", 7, false )
|| 0 == compare_strings( entry->extension, "mk", 3, false )
|| 0 == compare_strings( entry->name, "cmakelists.txt", 15, false );
} }
bool compare_archives( const directory_entry_t* const entry ) bool compare_archives( const directory_entry_t* const entry )
@@ -312,10 +333,17 @@ bool compare_sources( const directory_entry_t* const entry )
return 0 == compare_strings( entry->extension, "c", 2, true ) return 0 == compare_strings( entry->extension, "c", 2, true )
|| 0 == compare_strings( entry->extension, "cpp", 4, true ) || 0 == compare_strings( entry->extension, "cpp", 4, true )
|| 0 == compare_strings( entry->extension, "h", 2, true ) || 0 == compare_strings( entry->extension, "h", 2, true )
|| 0 == compare_strings( entry->extension, "rs", 3, true ) || 0 == compare_strings( entry->extension, "s", 2, false )
|| 0 == compare_strings( entry->extension, "tex", 4, true )
|| 0 == compare_strings( entry->extension, "zig", 4, true ) || 0 == compare_strings( entry->extension, "zig", 4, true )
|| 0 == compare_strings( entry->extension, "odin", 5, true ) || 0 == compare_strings( entry->extension, "odin", 5, true )
|| 0 == compare_strings( entry->extension, "py", 3, true ); || 0 == compare_strings( entry->extension, "py", 3, true )
|| 0 == compare_strings( entry->extension, "rs", 3, true );
}
bool compare_pdf( const directory_entry_t* const entry )
{
return 0 == compare_strings( entry->extension, "pdf", 4, true );
} }
void size_to_string( void size_to_string(
@@ -327,6 +355,7 @@ void size_to_string(
const char SIZE_CHARS[ 6 ] = { 'B', 'k', 'M', 'G', 'T', 'P' }; const char SIZE_CHARS[ 6 ] = { 'B', 'k', 'M', 'G', 'T', 'P' };
char size_quantifier = '\0'; char size_quantifier = '\0';
double size_format = ( float )entry->stats.st_size; double size_format = ( float )entry->stats.st_size;
if ( entry->stats.st_mode & S_IFREG if ( entry->stats.st_mode & S_IFREG
|| entry->stats.st_mode & S_IFCHR ) || entry->stats.st_mode & S_IFCHR )
{ {
@@ -366,7 +395,7 @@ void size_to_string(
snprintf( snprintf(
&file_size[ 0 ], &file_size[ 0 ],
length, length,
" " " -"
); );
} }
} }
+8 -7
View File
@@ -1,7 +1,3 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 700
#endif
// external dependencies // external dependencies
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@@ -15,9 +11,9 @@
#include <libgen.h> #include <libgen.h>
// internal dependencies // internal dependencies
#include "main.h"
#include "log.h" #include "log.h"
#include "arguments.h" #include "arguments.h"
#include "type_definitions.h"
#include "sorting.h" #include "sorting.h"
#include "display.h" #include "display.h"
@@ -122,7 +118,8 @@ int main( int argc, char** argv )
chdir( ".." ); chdir( ".." );
closedir( directory ); closedir( directory );
fputc( '\n', stdout ); if ( n < args.path_count - 1 )
fputc( '\n', stdout );
} }
return retval; return retval;
@@ -309,9 +306,13 @@ int handle_directory(
display_entry( entry, args ); display_entry( entry, args );
bool enter_git_dir = args->show_git_dir || strncmp( ".git", entry->name, 5 );
if ( args->tree_view if ( args->tree_view
&& recursion_level < args->depth && recursion_level < args->depth
&& entry->type == type_directory ) && entry->type == type_directory
&& enter_git_dir
)
{ {
DIR* subdirectory = opendir(entry->name); DIR* subdirectory = opendir(entry->name);
if ( !subdirectory ) if ( !subdirectory )
+5 -11
View File
@@ -1,15 +1,14 @@
#ifndef _XOPEN_SOURCE // external dependencies
#define _XOPEN_SOURCE 700
#endif
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
// internal dependencies
#include "main.h"
#include "sorting.h" #include "sorting.h"
#include "type_definitions.h"
#include "arguments.h" #include "arguments.h"
#include "log.h" #include "log.h"
#include "stringing.h" #include "stringing.h"
@@ -174,14 +173,9 @@ int compare_extension(
const void* operand_b const void* operand_b
) )
{ {
if ( !operand_a || !operand_b )
{
log_error( "invalid parameter to compare function" );
exit( -EINVAL );
}
directory_entry_t* a = *( directory_entry_t** )operand_a; directory_entry_t* a = *( directory_entry_t** )operand_a;
directory_entry_t* b = *( directory_entry_t** )operand_b; directory_entry_t* b = *( directory_entry_t** )operand_b;
if ( !a->extension && !b->extension ) return 0; if ( !a->extension && !b->extension ) return 0;
if ( !a->extension && b->extension ) return -1; if ( !a->extension && b->extension ) return -1;
if ( a->extension && !b->extension ) return 1; if ( a->extension && !b->extension ) return 1;