Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b91789df39 | ||
|
|
f2e3801b8a | ||
|
|
71f2709da4 | ||
|
|
3ad341e3c9 | ||
|
|
8772d10c4c | ||
|
|
46bf3c23c3 | ||
|
|
4d21f9e67d | ||
|
|
e5746c38bb | ||
|
|
6f28e63e3a | ||
|
|
079ccd4ed3 | ||
|
|
dfd525bed2 | ||
|
|
95fc4dec6a | ||
|
|
7a78bc6fc8 | ||
|
|
9b662f17bb | ||
|
|
62515e8a1b | ||
|
|
364ce8ea67 | ||
|
|
e536442616 |
No files matched your search
@@ -32,7 +32,7 @@ WCC := -Wconversion \
|
||||
|
||||
DEBUG_FLAGS := -O0 -g3
|
||||
|
||||
C_DEF :=
|
||||
C_DEF := _XOPEN_SOURCE=700
|
||||
|
||||
C_SRC := main.c \
|
||||
log.c \
|
||||
|
||||
+2
-1
@@ -36,13 +36,14 @@ typedef struct {
|
||||
bool show_all;
|
||||
bool show_almost_all;
|
||||
bool case_sensitive_sorting;
|
||||
size_t depth;
|
||||
bool no_colour;
|
||||
bool group_directories;
|
||||
bool display_help;
|
||||
bool long_view;
|
||||
bool reverse_order;
|
||||
bool tree_view;
|
||||
bool show_git_dir;
|
||||
size_t depth;
|
||||
permission_mode_t permission_mode;
|
||||
sorting_mode_t sorting_mode;
|
||||
time_mode_t time_mode;
|
||||
|
||||
+15
-7
@@ -55,20 +55,28 @@ const style_t socket_style[ SOCK_STYLE_NUM ] = { style_none };
|
||||
const uint32_t socket_colour = 0xEEEEEE;
|
||||
|
||||
#define EXEC_STYLE_NUM ( ( int )1 )
|
||||
const style_t exec_style[ EXEC_STYLE_NUM ] = { style_none };
|
||||
const uint32_t exec_colour = 0xEEEEEE;
|
||||
const style_t executable_style[ EXEC_STYLE_NUM ] = { style_bold };
|
||||
const uint32_t executable_colour = 0x34AD1F;
|
||||
|
||||
// files by extension
|
||||
#define MAKE_STYLE_NUM ( ( int )1 )
|
||||
const style_t makefile_style[ MAKE_STYLE_NUM ] = { style_none };
|
||||
#define MAKE_STYLE_NUM ( ( int )2 )
|
||||
const style_t makefile_style[ MAKE_STYLE_NUM ] = { style_bold, style_underlined };
|
||||
const uint32_t makefile_colour = 0xEAE977;
|
||||
|
||||
#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;
|
||||
|
||||
#define AR_STYLE_NUM ( ( int )1 )
|
||||
const style_t archive_style[ AR_STYLE_NUM ] = { style_none };
|
||||
const uint32_t archive_colour = 0xE02482;
|
||||
const style_t archive_style[ AR_STYLE_NUM ] = { style_bold };
|
||||
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
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#define __DISPLAY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "type_definitions.h"
|
||||
#include "main.h"
|
||||
#include "arguments.h"
|
||||
|
||||
void display_type( entry_type_t type, bool no_colour );
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
#ifndef __TYPE_DEFINITIONS_H
|
||||
#define __TYPE_DEFINITIONS_H
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#include <linux/limits.h>
|
||||
#include <sys/stat.h>
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#define __SORTING_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "type_definitions.h"
|
||||
#include "main.h"
|
||||
#include "arguments.h"
|
||||
|
||||
int sort_entries(
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# `scan`
|
||||
|
||||
This is a replacement for `ls` with additional features.
|
||||
Though it may result as a rewrite of `eza` (formerly `exa`).
|
||||
`scan` is a combination of `ls` and `tree`, with colouring by
|
||||
filetype.
|
||||
I wrote this as a fun side project and to replace `eza`
|
||||
(formerly `exa`) on my setup.
|
||||
@@ -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
@@ -14,6 +14,7 @@
|
||||
#define KEY_CASE_SENSITIVE ( ( int )'c' )
|
||||
#define KEY_DEPTH ( ( int )'d' )
|
||||
#define KEY_GROUP_DIRECTORIES ( ( int )'g' )
|
||||
#define KEY_SHOW_GIT_DIR ( ( int )'G' )
|
||||
#define KEY_HELP ( ( int )'h' )
|
||||
#define KEY_LONG_VIEW ( ( int )'l' )
|
||||
#define KEY_PERMISSIONS ( ( int )'p' )
|
||||
@@ -22,9 +23,11 @@
|
||||
#define KEY_TREE_VIEW ( ( int )'t' )
|
||||
#define KEY_TIME_MODE ( ( int )'T' )
|
||||
#define KEY_NO_COLOUR ( ( int )0x101 )
|
||||
#define KEY_COMPLETIONS ( ( int )0x102 )
|
||||
|
||||
// function prototypes
|
||||
static error_t arg_parser( int key, char* arg, struct argp_state* state );
|
||||
void print_completions( void );
|
||||
|
||||
// constant definitions
|
||||
const char* argp_program_version = "scan version 0.1";
|
||||
@@ -86,7 +89,15 @@ static struct argp_option options[] =
|
||||
.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,
|
||||
.arg = NULL,
|
||||
.flags = 0,
|
||||
@@ -141,6 +152,14 @@ static struct argp_option options[] =
|
||||
.doc = "time to display for directory entries",
|
||||
.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 ..
|
||||
};
|
||||
|
||||
@@ -165,6 +184,7 @@ void initialise_args( arguments_t* arguments )
|
||||
arguments->depth = MAX_TREE_DEPTH;
|
||||
arguments->no_colour = false;
|
||||
arguments->group_directories = false;
|
||||
arguments->show_git_dir = false;
|
||||
arguments->display_help = false;
|
||||
arguments->long_view = 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:
|
||||
arguments->group_directories = true;
|
||||
break;
|
||||
case KEY_SHOW_GIT_DIR:
|
||||
arguments->show_git_dir = true;
|
||||
break;
|
||||
case KEY_HELP:
|
||||
arguments->display_help = true;
|
||||
break;
|
||||
@@ -309,6 +332,9 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state )
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
break;
|
||||
case KEY_COMPLETIONS:
|
||||
print_completions();
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
if ( 0 == state->arg_num )
|
||||
arguments->path_count = 0u;
|
||||
@@ -322,3 +348,17 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state )
|
||||
|
||||
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
@@ -1,12 +1,10 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "display.h"
|
||||
#include "type_definitions.h"
|
||||
#include "main.h"
|
||||
#include "arguments.h"
|
||||
#include "log.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_archives( 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(
|
||||
const directory_entry_t* const entry,
|
||||
char* file_size,
|
||||
@@ -273,8 +272,12 @@ void set_file_style( const directory_entry_t* const entry )
|
||||
{
|
||||
if ( !entry ) return;
|
||||
|
||||
// makefiles and readmes
|
||||
if ( compare_makefile( entry ) )
|
||||
if ( entry->stats.st_mode & S_IXUSR )
|
||||
{
|
||||
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_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_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( ®ular_style[ 0 ], REG_STYLE_NUM );
|
||||
format_set_colour( regular_colour );
|
||||
}
|
||||
}
|
||||
|
||||
bool compare_makefile( const directory_entry_t* const entry )
|
||||
{
|
||||
return 0 == compare_strings( entry->name, "makefile", NAME_MAX, false )
|
||||
|| 0 == compare_strings( entry->name, "readme", 6, false )
|
||||
|| 0 == compare_strings( entry->extension, "mk", 3, false );
|
||||
return 0 == compare_strings( entry->name, "makefile", 9, false )
|
||||
|| 0 == compare_strings( entry->name, "readme", 7, 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 )
|
||||
@@ -312,10 +333,17 @@ bool compare_sources( const directory_entry_t* const entry )
|
||||
return 0 == compare_strings( entry->extension, "c", 2, true )
|
||||
|| 0 == compare_strings( entry->extension, "cpp", 4, 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, "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(
|
||||
@@ -327,6 +355,7 @@ void size_to_string(
|
||||
const char SIZE_CHARS[ 6 ] = { 'B', 'k', 'M', 'G', 'T', 'P' };
|
||||
char size_quantifier = '\0';
|
||||
double size_format = ( float )entry->stats.st_size;
|
||||
|
||||
if ( entry->stats.st_mode & S_IFREG
|
||||
|| entry->stats.st_mode & S_IFCHR )
|
||||
{
|
||||
@@ -366,7 +395,7 @@ void size_to_string(
|
||||
snprintf(
|
||||
&file_size[ 0 ],
|
||||
length,
|
||||
" "
|
||||
" -"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -1,7 +1,3 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
|
||||
// external dependencies
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -15,9 +11,9 @@
|
||||
#include <libgen.h>
|
||||
|
||||
// internal dependencies
|
||||
#include "main.h"
|
||||
#include "log.h"
|
||||
#include "arguments.h"
|
||||
#include "type_definitions.h"
|
||||
#include "sorting.h"
|
||||
#include "display.h"
|
||||
|
||||
@@ -122,6 +118,7 @@ int main( int argc, char** argv )
|
||||
chdir( ".." );
|
||||
closedir( directory );
|
||||
|
||||
if ( n < args.path_count - 1 )
|
||||
fputc( '\n', stdout );
|
||||
}
|
||||
|
||||
@@ -309,9 +306,13 @@ int handle_directory(
|
||||
|
||||
display_entry( entry, args );
|
||||
|
||||
bool enter_git_dir = args->show_git_dir || strncmp( ".git", entry->name, 5 );
|
||||
|
||||
if ( args->tree_view
|
||||
&& recursion_level < args->depth
|
||||
&& entry->type == type_directory )
|
||||
&& entry->type == type_directory
|
||||
&& enter_git_dir
|
||||
)
|
||||
{
|
||||
DIR* subdirectory = opendir(entry->name);
|
||||
if ( !subdirectory )
|
||||
|
||||
+5
-11
@@ -1,15 +1,14 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
|
||||
// external dependencies
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <linux/limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
// internal dependencies
|
||||
#include "main.h"
|
||||
#include "sorting.h"
|
||||
#include "type_definitions.h"
|
||||
#include "arguments.h"
|
||||
#include "log.h"
|
||||
#include "stringing.h"
|
||||
@@ -174,14 +173,9 @@ int compare_extension(
|
||||
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* b = *( directory_entry_t** )operand_b;
|
||||
|
||||
if ( !a->extension && !b->extension ) return 0;
|
||||
if ( !a->extension && b->extension ) return -1;
|
||||
if ( a->extension && !b->extension ) return 1;
|
||||
|
||||
Reference in new issue
Block a user