From c9c870db2ad06e6e364a8548dce8eb885d1fcafc Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:26:00 +0200 Subject: [PATCH 01/39] global overhaul --- main.sh | 297 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 178 insertions(+), 119 deletions(-) diff --git a/main.sh b/main.sh index f7c1be1..b72db15 100644 --- a/main.sh +++ b/main.sh @@ -1,124 +1,183 @@ #!/bin/env bash -clear -echo " -┌─────────────────────────────────────────────────┐ -│ %#### │ -│ ######### │ -│ @@@###@@# LinFM │ -│ @@@@@@@@@ A file manager, in your command line. │ -│ Made with <3 by [I> (Icycoide) │ -└─────────────────────────────────────────────────┘ -" -sleep 3 -echo "Loading contents from " $PWD"..." +consts() { + __TIFM_VERSION="0.1.0" +} -clear main() { - echo "┌─ Waiting for action at" $PWD - read -p "└─linfm> " lfm_ans - case "$lfm_ans" in - SetDir) - echo "Select a directory to go to." - read lfm_setdir - cd $lfm_setdir - main - ;; - Open) - echo "Choose a file to open." - read lfm_setfile - xdg-open $lfm_setfile - main - ;; - Copy) - echo "Choose the file and the location you would like to copy it to." - read lfm_setfile - cp $lfm_setfile - main - ;; - MoveFile) - echo "Choose the file and the new location you would like to move it to, with both of them being separated with a space." - read lfm_setfile - mv $lfm_setfile - main - ;; - Index) - ls -a - main - ;; - CreateFolder) - echo "Please put in the name of the folder you would like to create." - read lfm_setdir - mkdir $lfm_setdir - main - ;; - DeleteFile) - echo "Select the file you would like to delete. (Without confirmation.) To cancel, just press enter without typing in anything." - read lfm_setfile - rm $lfm_setfile - main - ;; - DeleteFolder) - echo "Select the folder you would like to delete. (Without confirmation.) To cancel, just press enter without typing in anything." - read lfm_setdir - rm -rf $lfm_setdir - main - ;; - TouchFile) - echo "Choose the name of the file..." - read lfm_setfile - touch $lfm_setfile - main - ;; - PermSet) - echo "Choose a file or folder to change the permission" - read lfm_setany - echo "Choose the arguments from 'chmod' to set as permission for the file or folder. (Read the manual for chmod for more info)" - read lfm_setperm - chmod $lfm_setperm $lfm_setany - main - ;; - CmdLine) - /bin/sh - main - ;; - Help) - echo " - List of commands: - SetDir - -Goes to a folder - Open - -Opens a file - MoveFile - -Moves/Renames a file - Copy - -Copies a file to a location - Index - -Shows the list of files inside the directory - CreateFolder - -Creates a folder - DeleteFile - -Deletes a File - DeleteFolder - -Deletes folder - TouchFile - -Creates new file - PermSet - -Sets permissions for a specific file or folder - CmdLine - -Switches to command line mode, run 'exit' to exit. - Exit - -That exits out of LinFM." - main - ;; - Exit) - clear - exit - ;; - *) - echo "Unrecognized command. Type 'Help' for a list of commands." - main - ;; - esac + echo "╭ $PWD" + while read file; do + echo "│ $file" + done < <(ls -1) + read -n 1 -p "╰ tifm> " ans + if [ "$ans" != "n" ] && [ "$ans" != "r" ]; then + echo "" + fi + case "$ans" in + N) + echo "Select a directory to go to (/cancel)." + read -p "nav:: " tifm_dir + if [ "$tifm_dir" == "/cancel" ]; then + echo "Cancelled." + return + else + cd $tifm_dir + fi + ;; + o) + echo "Choose a file to open (/cancel)." + read -p "from:: " tifm_file + if [ "$tifm_file" == "/cancel" ]; then + echo "Cancelled." + return + else + xdg-open $tifm_file + fi + ;; + c) + echo "Choose the file and the location you would like to copy it to (/cancel)." + read -p "from:: " tifm_file_from + if [ "$tifm_file_from" == "/cancel" ]; then + echo "Cancelled." + return + fi + read -p "to:: " tifm_file_to + if [ "$tifm_file_to" == "/cancel" ]; then + echo "Cancelled." + return + fi + cp "$tifm_file_from" "$tifm_file_to" + ;; + m) + echo "Choose the file and the new location you would like to move it to." + read -p "from:: " tifm_file_from + if [ "$tifm_file_from" == "/cancel" ]; then + echo "Cancelled." + return + fi + read -p "to:: " tifm_file_to + if [ "$tifm_file_to" == "/cancel" ]; then + echo "Cancelled." + return + fi + mv "$tifm_file_from" "$tifm_file_to" + ;; + i) + ls -l -1 + ;; + n) + read -n 1 tifm_type + echo "" + case "$tifm_type" in + d) + echo "Choose the directory you would like to create (/cancel)." + read -p "name:: " tifm_dir_name + if [ "$tifm_dir_name" == "/cancel" ]; then + echo "Cancelled." + return + fi + mkdir "$tifm_dir_name" + ;; + f) + echo "Choose the file you would like to create (/cancel)." + read -p "name:: " tifm_file_name + if [ "$tifm_file_name" == "/cancel" ]; then + echo "Cancelled." + return + fi + touch "$tifm_file_name" + ;; + *) + echo "Invalid type ([d]irectory/[f]ile)." + ;; + esac + ;; + r) + read -n 1 tifm_type + echo "" + case "$tifm_type" in + d) + echo "Choose the directory you would like to remove (/cancel)." + read -p "name:: " tifm_dir_name + if [ "$tifm_dir_name" == "/cancel" ]; then + echo "Cancelled." + return + fi + rm -rf "$tifm_dir_name" + ;; + f) + echo "Choose the file you would like to remove (/cancel)." + read -p "name:: " tifm_file_name + if [ "$tifm_file_name" == "/cancel" ]; then + echo "Cancelled." + return + fi + rm "$tifm_file_name" + ;; + *) + echo "Invalid type ([d]irectory/[f]ile)." + ;; + esac + ;; + p) + echo "Choose a file or folder to change the permission (/cancel)." + read -p "item:: " tifm_select + if [ "$tifm_select" == "/cancel" ]; then + echo "Cancelled." + return + fi + echo "Choose the arguments from 'chmod' to set as permission for the file or folder (/cancel). (Read the manual for chmod for more info)" + read -p "perm:: " tifm_perm + if [ "$tifm_perm" == "/cancel" ]; then + echo "Cancelled." + return + fi + chmod $tifm_perm $tifm_select + ;; + t) + /bin/bash + ;; + "?") + echo " + List of commands: + N + - Goes to a folder + o + - Opens a file + m + - Moves/Renames a file + c + - Copies a file to a location + i + - Shows the list of files inside the directory (with detail) + n + - Creates a folder or file + r + - Removes a folder or file + p + - Sets permissions for a specific file or folder + t + - Switches to command line mode, run 'exit' to exit. + Q + - Quits the program" + ;; + Q) + clear + exit + ;; + *) + echo "Unrecognized command. Type '?' for a list of commands." + ;; + esac } -main +( + consts + echo "╭ tifm $__TIFM_VERSION +│ github.com/Rexxt/tifm +╰ Strike '?' for help +" + echo "Loading contents from $PWD..." + while true; do + main + done +) From b1c69c09c4b5c5a0132ab4b488647fffcf83aec2 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:27:09 +0200 Subject: [PATCH 02/39] readme update --- README.md | 9 +++------ main.sh | 43 +++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 6958c80..8422e71 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -# linfm -Some sort of File Manager, made in the bash interpreter - -![Available on Paque](https://media.discordapp.net/attachments/655093392187064360/994649858810052668/InstallOnPaque.png) - -Package name: linfm +# tifm +a really **ti**ny **f**ile **m**anager +mostly meant for personal use and contribution to the project diff --git a/main.sh b/main.sh index b72db15..cca53ed 100644 --- a/main.sh +++ b/main.sh @@ -137,28 +137,27 @@ main() { /bin/bash ;; "?") - echo " - List of commands: - N - - Goes to a folder - o - - Opens a file - m - - Moves/Renames a file - c - - Copies a file to a location - i - - Shows the list of files inside the directory (with detail) - n - - Creates a folder or file - r - - Removes a folder or file - p - - Sets permissions for a specific file or folder - t - - Switches to command line mode, run 'exit' to exit. - Q - - Quits the program" + echo "List of commands: +N +- Goes to a folder +o +- Opens a file +m +- Moves/Renames a file +c +- Copies a file to a location +i +- Shows the list of files inside the directory (with detail) +n +- Creates a folder or file +r +- Removes a folder or file +p +- Sets permissions for a specific file or folder +t +- Switches to command line mode, run 'exit' to exit. +Q +- Quits the program" ;; Q) clear From e05b6c02cfe263349a58b97870d2a211a7203ed2 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:49:58 +0200 Subject: [PATCH 03/39] Colour, feature and config update --- config.sh | 2 ++ main.sh | 96 ++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 config.sh diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..2b2c79e --- /dev/null +++ b/config.sh @@ -0,0 +1,2 @@ +__TIFM_PAGER="less" # [p]eek command +__TIFM_EDITOR="nano" # [e]dit command \ No newline at end of file diff --git a/main.sh b/main.sh index cca53ed..d8987c4 100644 --- a/main.sh +++ b/main.sh @@ -1,17 +1,37 @@ #!/bin/env bash -consts() { +init() { + # consts __TIFM_VERSION="0.1.0" + BLACK=$(tput setaf 0) + RED=$(tput setaf 1) + GREEN=$(tput setaf 2) + YELLOW=$(tput setaf 3) + LIME_YELLOW=$(tput setaf 190) + POWDER_BLUE=$(tput setaf 153) + BLUE=$(tput setaf 4) + MAGENTA=$(tput setaf 5) + CYAN=$(tput setaf 6) + WHITE=$(tput setaf 7) + BRIGHT=$(tput bold) + NORMAL=$(tput sgr0) + BLINK=$(tput blink) + REVERSE=$(tput smso) + UNDERLINE=$(tput smul) + SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" + # config + source "$SCRIPT_DIR/config.sh" } main() { - echo "╭ $PWD" + echo "$CYAN╭ $BRIGHT$GREEN$PWD$NORMAL" while read file; do - echo "│ $file" + echo "$CYAN│ $BLUE$file$NORMAL" done < <(ls -1) - read -n 1 -p "╰ tifm> " ans + read -n 1 -p "$CYAN╰ ${RED}tifm> $YELLOW" ans if [ "$ans" != "n" ] && [ "$ans" != "r" ]; then echo "" fi + printf "$NORMAL" case "$ans" in N) echo "Select a directory to go to (/cancel)." @@ -33,6 +53,26 @@ main() { xdg-open $tifm_file fi ;; + p) + echo "Choose a file to view (/cancel)." + read -p "from:: " tifm_file + if [ "$tifm_file" == "/cancel" ]; then + echo "Cancelled." + return + else + $__TIFM_PAGER $tifm_file + fi + ;; + e) + echo "Choose a file to edit (/cancel)." + read -p "from:: " tifm_file + if [ "$tifm_file" == "/cancel" ]; then + echo "Cancelled." + return + else + $__TIFM_EDITOR $tifm_file + fi + ;; c) echo "Choose the file and the location you would like to copy it to (/cancel)." read -p "from:: " tifm_file_from @@ -118,7 +158,7 @@ main() { ;; esac ;; - p) + P) echo "Choose a file or folder to change the permission (/cancel)." read -p "item:: " tifm_select if [ "$tifm_select" == "/cancel" ]; then @@ -137,27 +177,19 @@ main() { /bin/bash ;; "?") - echo "List of commands: -N -- Goes to a folder -o -- Opens a file -m -- Moves/Renames a file -c -- Copies a file to a location -i -- Shows the list of files inside the directory (with detail) -n -- Creates a folder or file -r -- Removes a folder or file -p -- Sets permissions for a specific file or folder -t -- Switches to command line mode, run 'exit' to exit. -Q -- Quits the program" + echo "${LIME_YELLOW}List of commands:$NORMAL +N - Goes to a folder +o - Opens a file +p - View file (uses 'less' by default - change in config.sh) +e - edit a file (uses 'nano' by default - change in config.sh) +m - Moves/Renames a file +c - Copies a file to a location +i - Shows the list of files inside the directory (with detail) +n(f/d) - Creates a folder or file +r(f/d) - Removes a folder or file +P - Sets permissions for a specific file or folder +t - Switches to command line mode, run 'exit' to exit. +Q - Quits the program" ;; Q) clear @@ -170,12 +202,12 @@ Q } ( - consts - echo "╭ tifm $__TIFM_VERSION -│ github.com/Rexxt/tifm -╰ Strike '?' for help -" - echo "Loading contents from $PWD..." + clear + init + echo "$CYAN╭$NORMAL tifm $__TIFM_VERSION +$CYAN│$NORMAL github.com/Rexxt/tifm +$CYAN╰$NORMAL Strike '?' for help" + echo "" while true; do main done From 5cd41e0a4b75c639729ea97dd4b4a97bbe613850 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:52:17 +0200 Subject: [PATCH 04/39] woops i fucked up --- main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.sh b/main.sh index d8987c4..9ae310c 100644 --- a/main.sh +++ b/main.sh @@ -181,7 +181,7 @@ main() { N - Goes to a folder o - Opens a file p - View file (uses 'less' by default - change in config.sh) -e - edit a file (uses 'nano' by default - change in config.sh) +e - edit a file (uses 'nano' by default - change in config.sh) m - Moves/Renames a file c - Copies a file to a location i - Shows the list of files inside the directory (with detail) From 237d91fdf4043001d1a7db3d30c157a0eb950771 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:53:01 +0200 Subject: [PATCH 05/39] aeration --- main.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/main.sh b/main.sh index 9ae310c..dc83ccd 100644 --- a/main.sh +++ b/main.sh @@ -199,6 +199,7 @@ Q - Quits the program" echo "Unrecognized command. Type '?' for a list of commands." ;; esac + echo "" } ( From b6e6ae03a74214bc21f7e5c3470911f0658a18f6 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:59:50 +0200 Subject: [PATCH 06/39] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8422e71..9edb319 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # tifm a really **ti**ny **f**ile **m**anager -mostly meant for personal use and contribution to the project +mostly meant for personal use and contribution to the parent project From b4adc1938ac149564bb5badc8fface1f38d3b35e Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 19:03:16 +0200 Subject: [PATCH 07/39] made characters configurable --- config.sh | 7 ++++++- main.sh | 15 +++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/config.sh b/config.sh index 2b2c79e..29dcb5a 100644 --- a/config.sh +++ b/config.sh @@ -1,2 +1,7 @@ __TIFM_PAGER="less" # [p]eek command -__TIFM_EDITOR="nano" # [e]dit command \ No newline at end of file +__TIFM_EDITOR="nano" # [e]dit command +__ANGLE_UP_RIGHT="╭" +__ANGLE_UP_LEFT="╮" +__ANGLE_DOWN_RIGHT="╰" +__ANGLE_DOWN_LEFT="╯" +__VBAR="│" \ No newline at end of file diff --git a/main.sh b/main.sh index dc83ccd..992c914 100644 --- a/main.sh +++ b/main.sh @@ -20,14 +20,16 @@ init() { SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" # config source "$SCRIPT_DIR/config.sh" + # vars + STATUS=0 } main() { - echo "$CYAN╭ $BRIGHT$GREEN$PWD$NORMAL" + echo "$CYAN$__ANGLE_UP_RIGHT $BRIGHT$GREEN$PWD$NORMAL $STATUS" while read file; do - echo "$CYAN│ $BLUE$file$NORMAL" + echo "$CYAN$__VBAR $BLUE$file$NORMAL" done < <(ls -1) - read -n 1 -p "$CYAN╰ ${RED}tifm> $YELLOW" ans + read -n 1 -p "$CYAN$__ANGLE_DOWN_RIGHT ${RED}tifm> $YELLOW" ans if [ "$ans" != "n" ] && [ "$ans" != "r" ]; then echo "" fi @@ -199,15 +201,16 @@ Q - Quits the program" echo "Unrecognized command. Type '?' for a list of commands." ;; esac + STATUS=$? echo "" } ( clear init - echo "$CYAN╭$NORMAL tifm $__TIFM_VERSION -$CYAN│$NORMAL github.com/Rexxt/tifm -$CYAN╰$NORMAL Strike '?' for help" + echo "$CYAN$__ANGLE_UP_RIGHT$NORMAL tifm $__TIFM_VERSION +$CYAN$__VBAR$NORMAL github.com/Rexxt/tifm +$CYAN$__ANGLE_DOWN_RIGHT$NORMAL Strike '?' for help" echo "" while true; do main From b649a704f4f01d20e02705590113d9d863a4c213 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 19:24:52 +0200 Subject: [PATCH 08/39] unhealthy amounts of customizability --- config.sh | 16 +++++++++++++++- main.sh | 18 +++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/config.sh b/config.sh index 29dcb5a..4457e33 100644 --- a/config.sh +++ b/config.sh @@ -4,4 +4,18 @@ __ANGLE_UP_RIGHT="╭" __ANGLE_UP_LEFT="╮" __ANGLE_DOWN_RIGHT="╰" __ANGLE_DOWN_LEFT="╯" -__VBAR="│" \ No newline at end of file +__VBAR="│" +__TIFM_DECO_COLOUR="$CYAN" +__TIFM_DISPLAY() { + local stat="" + if [ "$STATUS" == "0" ]; then + stat="${GREEN}✓$NORMAL" + else + stat="${RED}× $STATUS$NORMAL" + fi + echo "$GREEN$BRIGHT$PWD$NORMAL $stat" +} +__TIFM_LS_COLOUR="$BLUE" +__TIFM_PROMPT() { + echo "${CYAN}tifm>" +} \ No newline at end of file diff --git a/main.sh b/main.sh index 992c914..37111cc 100644 --- a/main.sh +++ b/main.sh @@ -18,18 +18,18 @@ init() { REVERSE=$(tput smso) UNDERLINE=$(tput smul) SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" - # config - source "$SCRIPT_DIR/config.sh" # vars STATUS=0 + # config + source "$SCRIPT_DIR/config.sh" } main() { - echo "$CYAN$__ANGLE_UP_RIGHT $BRIGHT$GREEN$PWD$NORMAL $STATUS" + echo "$__TIFM_DECO_COLOUR$__ANGLE_UP_RIGHT $(__TIFM_DISPLAY)$NORMAL" while read file; do - echo "$CYAN$__VBAR $BLUE$file$NORMAL" - done < <(ls -1) - read -n 1 -p "$CYAN$__ANGLE_DOWN_RIGHT ${RED}tifm> $YELLOW" ans + echo "$__TIFM_DECO_COLOUR$__VBAR $__TIFM_LS_COLOUR$file$NORMAL" + done < <(ls -a) + read -n 1 -p "$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT $(__TIFM_PROMPT) $YELLOW" ans if [ "$ans" != "n" ] && [ "$ans" != "r" ]; then echo "" fi @@ -208,9 +208,9 @@ Q - Quits the program" ( clear init - echo "$CYAN$__ANGLE_UP_RIGHT$NORMAL tifm $__TIFM_VERSION -$CYAN$__VBAR$NORMAL github.com/Rexxt/tifm -$CYAN$__ANGLE_DOWN_RIGHT$NORMAL Strike '?' for help" + echo "$__TIFM_DECO_COLOUR$__ANGLE_UP_RIGHT$NORMAL tifm $__TIFM_VERSION +$__TIFM_DECO_COLOUR$__VBAR$NORMAL github.com/Rexxt/tifm +$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT$NORMAL Strike '?' for help" echo "" while true; do main From a875b516baa404a3848a7880ca4a5f32f8802234 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 16 Aug 2022 21:08:28 +0200 Subject: [PATCH 09/39] extensions wip --- config.sh | 2 +- extensions/hello.sh | 8 +++++++ main.sh | 54 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 extensions/hello.sh diff --git a/config.sh b/config.sh index 4457e33..8a94b42 100644 --- a/config.sh +++ b/config.sh @@ -17,5 +17,5 @@ __TIFM_DISPLAY() { } __TIFM_LS_COLOUR="$BLUE" __TIFM_PROMPT() { - echo "${CYAN}tifm>" + echo "$CYAN$USERNAME>" } \ No newline at end of file diff --git a/extensions/hello.sh b/extensions/hello.sh new file mode 100644 index 0000000..5359e31 --- /dev/null +++ b/extensions/hello.sh @@ -0,0 +1,8 @@ +greet_user() { + echo "Hello $USERNAME!" +} +greet_world() { + echo "Hello, world!" +} +tifmx.bind u greet_user +tifmx.bind w greet_world \ No newline at end of file diff --git a/main.sh b/main.sh index 37111cc..9e42a9f 100644 --- a/main.sh +++ b/main.sh @@ -1,7 +1,7 @@ #!/bin/env bash init() { # consts - __TIFM_VERSION="0.1.0" + __TIFM_VERSION="0.1.1" BLACK=$(tput setaf 0) RED=$(tput setaf 1) GREEN=$(tput setaf 2) @@ -22,6 +22,27 @@ init() { STATUS=0 # config source "$SCRIPT_DIR/config.sh" + # load extensions + declare -A tifm_extensions_commands + tifm_extensions_longcommands=() + declare -A tifm_extensions_subcommands + tifmx.bind() { + tifm_extensions_commands["$1"]="$2" + } + tifmx.add_long() { + tifm_extensions_longcommands+=("$1") + } + tifmx.bind_sub() { + tifm_extensions_subcommands["$1$2"]="$3" + } + load_extensions +} + +load_extensions() { + for extension in "$SCRIPT_DIR/extensions/"*; do + source "$extension" + done + echo "${tifm_extensions_commands[@]}, ${tifm_extensions_longcommands[@]}, ${tifm_extensions_subcommands[@]}" } main() { @@ -30,7 +51,7 @@ main() { echo "$__TIFM_DECO_COLOUR$__VBAR $__TIFM_LS_COLOUR$file$NORMAL" done < <(ls -a) read -n 1 -p "$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT $(__TIFM_PROMPT) $YELLOW" ans - if [ "$ans" != "n" ] && [ "$ans" != "r" ]; then + if [ "$ans" != "n" ] && [ "$ans" != "r" ] && [ -z "${tifm_extensions_longcommands[$tifm_select]}" ]; then echo "" fi printf "$NORMAL" @@ -47,7 +68,7 @@ main() { ;; o) echo "Choose a file to open (/cancel)." - read -p "from:: " tifm_file + read -p "file:: " tifm_file if [ "$tifm_file" == "/cancel" ]; then echo "Cancelled." return @@ -57,7 +78,7 @@ main() { ;; p) echo "Choose a file to view (/cancel)." - read -p "from:: " tifm_file + read -p "file:: " tifm_file if [ "$tifm_file" == "/cancel" ]; then echo "Cancelled." return @@ -67,7 +88,7 @@ main() { ;; e) echo "Choose a file to edit (/cancel)." - read -p "from:: " tifm_file + read -p "file:: " tifm_file if [ "$tifm_file" == "/cancel" ]; then echo "Cancelled." return @@ -104,7 +125,14 @@ main() { mv "$tifm_file_from" "$tifm_file_to" ;; i) - ls -l -1 + echo "Choose the directory to inspect (/cancel)." + read -p "dir:: " tifm_dir + if [ "$tifm_dir" == "/cancel" ]; then + echo "Cancelled." + return + else + ls -l $tifm_dir + fi ;; n) read -n 1 tifm_type @@ -198,7 +226,19 @@ Q - Quits the program" exit ;; *) - echo "Unrecognized command. Type '?' for a list of commands." + if [ ! -z "${tifm_extensions_commands[$tifm_select]}" ]; then + eval "${tifm_extensions_commands[$tifm_select]}" + elif [ ! -z "${tifm_extensions_longcommands[$tifm_select]}" ]; then + read -n 1 tifm_subcommand + echo "" + if [ ! -z "${tifm_extensions_subcommands[$tifm_select$tifm_subcommand]}" ]; then + eval "${tifm_extensions_subcommands[$tifm_select$tifm_subcommand]}" + else + echo "Invalid subcommand." + fi + else + echo "Unrecognized command. Type '?' for a list of commands." + fi ;; esac STATUS=$? From 95b7d203977ab7c2af1f1986133cd619bb32a63b Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 17 Aug 2022 15:40:43 +0200 Subject: [PATCH 10/39] after quite a bit of fixing, extensions work! --- .gitignore | 1 + extensions/hello.sh | 7 ++- main.sh | 115 ++++++++++++++++++++++++-------------------- 3 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a23c80 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +extensions/hello.sh \ No newline at end of file diff --git a/extensions/hello.sh b/extensions/hello.sh index 5359e31..d6ea0cc 100644 --- a/extensions/hello.sh +++ b/extensions/hello.sh @@ -4,5 +4,8 @@ greet_user() { greet_world() { echo "Hello, world!" } -tifmx.bind u greet_user -tifmx.bind w greet_world \ No newline at end of file +# tifmx.bind u greet_user +# tifmx.bind w greet_world +tifmx.add_long g +tifmx.bind_sub g u greet_user +tifmx.bind_sub g w greet_world \ No newline at end of file diff --git a/main.sh b/main.sh index 9e42a9f..9c937a9 100644 --- a/main.sh +++ b/main.sh @@ -1,48 +1,59 @@ #!/bin/env bash +declare -A -x tifm_extensions_commands +declare -a -x tifm_extensions_longcommands=() +declare -A -x tifm_extensions_subcommands +tifmx.bind() { + tifm_extensions_commands["$1"]="$2" +} +tifmx.add_long() { + tifm_extensions_longcommands+=("$1") +} +tifmx.bind_sub() { + tifm_extensions_subcommands["$1$2"]="$3" +} +# consts +__TIFM_VERSION="0.1.1" +BLACK=$(tput setaf 0) +RED=$(tput setaf 1) +GREEN=$(tput setaf 2) +YELLOW=$(tput setaf 3) +LIME_YELLOW=$(tput setaf 190) +POWDER_BLUE=$(tput setaf 153) +BLUE=$(tput setaf 4) +MAGENTA=$(tput setaf 5) +CYAN=$(tput setaf 6) +WHITE=$(tput setaf 7) +BRIGHT=$(tput bold) +NORMAL=$(tput sgr0) +BLINK=$(tput blink) +REVERSE=$(tput smso) +UNDERLINE=$(tput smul) +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" + init() { - # consts - __TIFM_VERSION="0.1.1" - BLACK=$(tput setaf 0) - RED=$(tput setaf 1) - GREEN=$(tput setaf 2) - YELLOW=$(tput setaf 3) - LIME_YELLOW=$(tput setaf 190) - POWDER_BLUE=$(tput setaf 153) - BLUE=$(tput setaf 4) - MAGENTA=$(tput setaf 5) - CYAN=$(tput setaf 6) - WHITE=$(tput setaf 7) - BRIGHT=$(tput bold) - NORMAL=$(tput sgr0) - BLINK=$(tput blink) - REVERSE=$(tput smso) - UNDERLINE=$(tput smul) - SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" # vars STATUS=0 # config source "$SCRIPT_DIR/config.sh" # load extensions - declare -A tifm_extensions_commands - tifm_extensions_longcommands=() - declare -A tifm_extensions_subcommands - tifmx.bind() { - tifm_extensions_commands["$1"]="$2" - } - tifmx.add_long() { - tifm_extensions_longcommands+=("$1") - } - tifmx.bind_sub() { - tifm_extensions_subcommands["$1$2"]="$3" - } + tput sc + printf "Loading extensions... " load_extensions + printf "Done.\n" } load_extensions() { + local count=0 + # check how many files are in the extensions directory + local files=$(ls -1 "$SCRIPT_DIR/extensions" | wc -l) for extension in "$SCRIPT_DIR/extensions/"*; do source "$extension" + count=$((count + 1)) + # percentage of completion + local percent=$((count / files * 100)) + tput rc + printf "Loading extensions... $count/$files ($percent%%)\n" done - echo "${tifm_extensions_commands[@]}, ${tifm_extensions_longcommands[@]}, ${tifm_extensions_subcommands[@]}" } main() { @@ -51,7 +62,7 @@ main() { echo "$__TIFM_DECO_COLOUR$__VBAR $__TIFM_LS_COLOUR$file$NORMAL" done < <(ls -a) read -n 1 -p "$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT $(__TIFM_PROMPT) $YELLOW" ans - if [ "$ans" != "n" ] && [ "$ans" != "r" ] && [ -z "${tifm_extensions_longcommands[$tifm_select]}" ]; then + if [[ "$ans" != "n" ]] && [[ "$ans" != "r" ]] && [[ ! "${tifm_extensions_longcommands[*]}" =~ "$ans" ]]; then echo "" fi printf "$NORMAL" @@ -59,7 +70,7 @@ main() { N) echo "Select a directory to go to (/cancel)." read -p "nav:: " tifm_dir - if [ "$tifm_dir" == "/cancel" ]; then + if [[ "$tifm_dir" == "/cancel" ]]; then echo "Cancelled." return else @@ -69,7 +80,7 @@ main() { o) echo "Choose a file to open (/cancel)." read -p "file:: " tifm_file - if [ "$tifm_file" == "/cancel" ]; then + if [[ "$tifm_file" == "/cancel" ]]; then echo "Cancelled." return else @@ -79,7 +90,7 @@ main() { p) echo "Choose a file to view (/cancel)." read -p "file:: " tifm_file - if [ "$tifm_file" == "/cancel" ]; then + if [[ "$tifm_file" == "/cancel" ]]; then echo "Cancelled." return else @@ -89,7 +100,7 @@ main() { e) echo "Choose a file to edit (/cancel)." read -p "file:: " tifm_file - if [ "$tifm_file" == "/cancel" ]; then + if [[ "$tifm_file" == "/cancel" ]]; then echo "Cancelled." return else @@ -99,12 +110,12 @@ main() { c) echo "Choose the file and the location you would like to copy it to (/cancel)." read -p "from:: " tifm_file_from - if [ "$tifm_file_from" == "/cancel" ]; then + if [[ "$tifm_file_from" == "/cancel" ]]; then echo "Cancelled." return fi read -p "to:: " tifm_file_to - if [ "$tifm_file_to" == "/cancel" ]; then + if [[ "$tifm_file_to" == "/cancel" ]]; then echo "Cancelled." return fi @@ -113,12 +124,12 @@ main() { m) echo "Choose the file and the new location you would like to move it to." read -p "from:: " tifm_file_from - if [ "$tifm_file_from" == "/cancel" ]; then + if [[ "$tifm_file_from" == "/cancel" ]]; then echo "Cancelled." return fi read -p "to:: " tifm_file_to - if [ "$tifm_file_to" == "/cancel" ]; then + if [[ "$tifm_file_to" == "/cancel" ]]; then echo "Cancelled." return fi @@ -127,7 +138,7 @@ main() { i) echo "Choose the directory to inspect (/cancel)." read -p "dir:: " tifm_dir - if [ "$tifm_dir" == "/cancel" ]; then + if [[ "$tifm_dir" == "/cancel" ]]; then echo "Cancelled." return else @@ -141,7 +152,7 @@ main() { d) echo "Choose the directory you would like to create (/cancel)." read -p "name:: " tifm_dir_name - if [ "$tifm_dir_name" == "/cancel" ]; then + if [[ "$tifm_dir_name" == "/cancel" ]]; then echo "Cancelled." return fi @@ -150,7 +161,7 @@ main() { f) echo "Choose the file you would like to create (/cancel)." read -p "name:: " tifm_file_name - if [ "$tifm_file_name" == "/cancel" ]; then + if [[ "$tifm_file_name" == "/cancel" ]]; then echo "Cancelled." return fi @@ -168,7 +179,7 @@ main() { d) echo "Choose the directory you would like to remove (/cancel)." read -p "name:: " tifm_dir_name - if [ "$tifm_dir_name" == "/cancel" ]; then + if [[ "$tifm_dir_name" == "/cancel" ]]; then echo "Cancelled." return fi @@ -177,7 +188,7 @@ main() { f) echo "Choose the file you would like to remove (/cancel)." read -p "name:: " tifm_file_name - if [ "$tifm_file_name" == "/cancel" ]; then + if [[ "$tifm_file_name" == "/cancel" ]]; then echo "Cancelled." return fi @@ -191,13 +202,13 @@ main() { P) echo "Choose a file or folder to change the permission (/cancel)." read -p "item:: " tifm_select - if [ "$tifm_select" == "/cancel" ]; then + if [[ "$tifm_select" == "/cancel" ]]; then echo "Cancelled." return fi echo "Choose the arguments from 'chmod' to set as permission for the file or folder (/cancel). (Read the manual for chmod for more info)" read -p "perm:: " tifm_perm - if [ "$tifm_perm" == "/cancel" ]; then + if [[ "$tifm_perm" == "/cancel" ]]; then echo "Cancelled." return fi @@ -226,13 +237,13 @@ Q - Quits the program" exit ;; *) - if [ ! -z "${tifm_extensions_commands[$tifm_select]}" ]; then - eval "${tifm_extensions_commands[$tifm_select]}" - elif [ ! -z "${tifm_extensions_longcommands[$tifm_select]}" ]; then + if [[ ! -z "${tifm_extensions_commands[$ans]}" ]]; then + eval "${tifm_extensions_commands[$ans]}" + elif [[ "${tifm_extensions_longcommands[*]}" =~ "$ans" ]]; then read -n 1 tifm_subcommand echo "" - if [ ! -z "${tifm_extensions_subcommands[$tifm_select$tifm_subcommand]}" ]; then - eval "${tifm_extensions_subcommands[$tifm_select$tifm_subcommand]}" + if [[ ! -z "${tifm_extensions_subcommands[$ans$tifm_subcommand]}" ]]; then + eval "${tifm_extensions_subcommands[$ans$tifm_subcommand]}" else echo "Invalid subcommand." fi From 83f48929ea92cb54196d1e0a971a3d41813bea39 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:05:27 +0200 Subject: [PATCH 11/39] little tweaks, also working on a git extension --- extensions/git.sh | 3 +++ extensions/hello.sh | 11 ----------- main.sh | 23 ++++++++++++++++++----- 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 extensions/git.sh delete mode 100644 extensions/hello.sh diff --git a/extensions/git.sh b/extensions/git.sh new file mode 100644 index 0000000..29de6c3 --- /dev/null +++ b/extensions/git.sh @@ -0,0 +1,3 @@ +# git.sh +# adds git support to tifm + diff --git a/extensions/hello.sh b/extensions/hello.sh deleted file mode 100644 index d6ea0cc..0000000 --- a/extensions/hello.sh +++ /dev/null @@ -1,11 +0,0 @@ -greet_user() { - echo "Hello $USERNAME!" -} -greet_world() { - echo "Hello, world!" -} -# tifmx.bind u greet_user -# tifmx.bind w greet_world -tifmx.add_long g -tifmx.bind_sub g u greet_user -tifmx.bind_sub g w greet_world \ No newline at end of file diff --git a/main.sh b/main.sh index 9c937a9..98ece35 100644 --- a/main.sh +++ b/main.sh @@ -1,6 +1,7 @@ #!/bin/env bash +declare -a -x tifm_extensions declare -A -x tifm_extensions_commands -declare -a -x tifm_extensions_longcommands=() +declare -a -x tifm_extensions_longcommands declare -A -x tifm_extensions_subcommands tifmx.bind() { tifm_extensions_commands["$1"]="$2" @@ -12,7 +13,7 @@ tifmx.bind_sub() { tifm_extensions_subcommands["$1$2"]="$3" } # consts -__TIFM_VERSION="0.1.1" +__TIFM_VERSION="0.2.0" BLACK=$(tput setaf 0) RED=$(tput setaf 1) GREEN=$(tput setaf 2) @@ -28,6 +29,7 @@ NORMAL=$(tput sgr0) BLINK=$(tput blink) REVERSE=$(tput smso) UNDERLINE=$(tput smul) +DIM=$(tput dim) SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" init() { @@ -48,6 +50,8 @@ load_extensions() { local files=$(ls -1 "$SCRIPT_DIR/extensions" | wc -l) for extension in "$SCRIPT_DIR/extensions/"*; do source "$extension" + # add only the name of the extension to the array (ex: extensions/git.sh -> git) + tifm_extensions+=("$(basename "$extension")") count=$((count + 1)) # percentage of completion local percent=$((count / files * 100)) @@ -217,6 +221,12 @@ main() { t) /bin/bash ;; + ";") + # open config + $__TIFM_EDITOR "$SCRIPT_DIR/config.sh" + # reload config + source "$SCRIPT_DIR/config.sh" + ;; "?") echo "${LIME_YELLOW}List of commands:$NORMAL N - Goes to a folder @@ -230,6 +240,7 @@ n(f/d) - Creates a folder or file r(f/d) - Removes a folder or file P - Sets permissions for a specific file or folder t - Switches to command line mode, run 'exit' to exit. +; - Open config file Q - Quits the program" ;; Q) @@ -259,9 +270,11 @@ Q - Quits the program" ( clear init - echo "$__TIFM_DECO_COLOUR$__ANGLE_UP_RIGHT$NORMAL tifm $__TIFM_VERSION -$__TIFM_DECO_COLOUR$__VBAR$NORMAL github.com/Rexxt/tifm -$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT$NORMAL Strike '?' for help" + echo "$__TIFM_DECO_COLOUR$__ANGLE_UP_RIGHT$GREEN tifm $__TIFM_VERSION$NORMAL +$__TIFM_DECO_COLOUR$__VBAR$NORMAL $BLUE${UNDERLINE}https://github.com/Rexxt/tifm$NORMAL +$__TIFM_DECO_COLOUR$__VBAR$NORMAL $RED$REVERSE/!\\ you are running a bleeding edge version of tifm. $NORMAL +$__TIFM_DECO_COLOUR$__VBAR$NORMAL $RED$REVERSE if you encounter any bugs, report them on github.$NORMAL +$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT$NORMAL strike '?' for help" echo "" while true; do main From 78ae6fa0557d127e67a555a978d6255447c45e66 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:37:01 +0200 Subject: [PATCH 12/39] improving extension support and working on git extension --- config.sh | 9 +++++- extensions/git.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++ main.sh | 73 ++++++++++++++++++++++++----------------- 3 files changed, 133 insertions(+), 31 deletions(-) diff --git a/config.sh b/config.sh index 8a94b42..ca7d7a7 100644 --- a/config.sh +++ b/config.sh @@ -13,7 +13,14 @@ __TIFM_DISPLAY() { else stat="${RED}× $STATUS$NORMAL" fi - echo "$GREEN$BRIGHT$PWD$NORMAL $stat" + local string="$GREEN$BRIGHT$PWD$NORMAL $stat " + # for each extension, if it has a display function, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".display &> /dev/null; then + string="$string$( "$ext_name".display )$NORMAL " + fi + done + echo "$string" } __TIFM_LS_COLOUR="$BLUE" __TIFM_PROMPT() { diff --git a/extensions/git.sh b/extensions/git.sh index 29de6c3..4c442ab 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -1,3 +1,85 @@ # git.sh # adds git support to tifm +__tifmgit_in_repo=false +is_git_repo() { + # check if current directory is a git repo + git rev-parse --is-inside-work-tree &> /dev/null +} + +git.init() { + # check if current directory is a git repo + if is_git_repo; then + __tifmgit_in_repo=true + fi +} + +git.nav() { + if is_git_repo; then + __tifmgit_in_repo=true + fi +} + +git.display() { + # display git status + if $__tifmgit_in_repo; then + local branch=$(git rev-parse --abbrev-ref HEAD) + local gstatus=$(git status --porcelain) + # replace newlines with , + gstatus=$(echo "$gstatus" | tr '\n' ',') + # remove leading and trailing spaces + gstatus=$(echo "$gstatus" | sed 's/^ *//g;s/ *$//g') + # remove trailing , + gstatus=$(echo "$gstatus" | sed 's/,$//g') + echo "$BRIGHT$YELLOW(git branch $branch - status: $gstatus)$NORMAL" + fi +} + +git_pull() { + # pull from remote + git pull +} +git_push() { + # push to remote + git push +} +git_status() { + # display git status + if $__tifmgit_in_repo; then + local branch=$(git rev-parse --abbrev-ref HEAD) + local gstatus=$(git status --porcelain) + # colouring + # M file -> ${BLUE}M${NORMAL}file + gstatus=$(echo "$gstatus" | sed "s/ M /${BLUE}M${NORMAL} /g") + # A file -> ${GREEN}A${NORMAL}file + gstatus=$(echo "$gstatus" | sed "s/ A /${GREEN}A${NORMAL} /g") + # D file -> ${RED}D${NORMAL}file + gstatus=$(echo "$gstatus" | sed "s/ D /${RED}D${NORMAL} /g") + # R file -> ${YELLOW}R${NORMAL}file + gstatus=$(echo "$gstatus" | sed "s/ R /${YELLOW}R${NORMAL} /g") + # C file -> ${LIME_YELLOW}C${NORMAL}file + gstatus=$(echo "$gstatus" | sed "s/ C /${LIME_YELLOW}C${NORMAL} /g") + # U file -> ${POWDER_BLUE}U${NORMAL}file + gstatus=$(echo "$gstatus" | sed "s/ U /${POWDER_BLUE}U${NORMAL} /g") + # ? file -> ${MAGENTA}?${NORMAL}file + gstatus=$(echo "$gstatus" | sed "s/ ? /${MAGENTA}?${NORMAL} /g") + # ! file -> ${CYAN}!${NORMAL}file + gstatus=$(echo "$gstatus" | sed "s/ ! /${CYAN}!${NORMAL} /g") + echo -e "$BRIGHT${YELLOW}git branch $branch$NORMAL\n$gstatus" + fi +} +git_add() { + # add all files to git + git add . +} +git_commit() { + # commit all files to git + read -p "Commit message: " message + git commit -m "$message" +} +tifmx.add_long G # for global git commands +tifmx.bind_sub G p git_pull +tifmx.bind_sub G P git_push +tifmx.bind_sub G s git_status +tifmx.bind_sub G a git_add +tifmx.bind_sub G c git_commit \ No newline at end of file diff --git a/main.sh b/main.sh index 98ece35..0c065ed 100644 --- a/main.sh +++ b/main.sh @@ -51,12 +51,17 @@ load_extensions() { for extension in "$SCRIPT_DIR/extensions/"*; do source "$extension" # add only the name of the extension to the array (ex: extensions/git.sh -> git) - tifm_extensions+=("$(basename "$extension")") + local ext_name=$(basename "$extension" | cut -d. -f1) + tifm_extensions+=("$ext_name") count=$((count + 1)) # percentage of completion local percent=$((count / files * 100)) tput rc printf "Loading extensions... $count/$files ($percent%%)\n" + # if function $ext_name.init exists, call it + if type "$ext_name".init &> /dev/null; then + "$ext_name".init + fi done } @@ -66,25 +71,33 @@ main() { echo "$__TIFM_DECO_COLOUR$__VBAR $__TIFM_LS_COLOUR$file$NORMAL" done < <(ls -a) read -n 1 -p "$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT $(__TIFM_PROMPT) $YELLOW" ans + if [[ "$ans" != "n" ]] && [[ "$ans" != "r" ]] && [[ ! "${tifm_extensions_longcommands[*]}" =~ "$ans" ]]; then echo "" fi printf "$NORMAL" + case "$ans" in N) - echo "Select a directory to go to (/cancel)." + echo "Select a directory to go to (/c(ancel))." read -p "nav:: " tifm_dir - if [[ "$tifm_dir" == "/cancel" ]]; then + if [[ "$tifm_dir" == "/c" ]]; then echo "Cancelled." return else cd $tifm_dir + # for ever extension, if it has a function called name.nav, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".nav &> /dev/null; then + "$ext_name".nav + fi + done fi ;; o) - echo "Choose a file to open (/cancel)." + echo "Choose a file to open (/c(ancel))." read -p "file:: " tifm_file - if [[ "$tifm_file" == "/cancel" ]]; then + if [[ "$tifm_file" == "/c" ]]; then echo "Cancelled." return else @@ -92,9 +105,9 @@ main() { fi ;; p) - echo "Choose a file to view (/cancel)." + echo "Choose a file to view (/c(ancel))." read -p "file:: " tifm_file - if [[ "$tifm_file" == "/cancel" ]]; then + if [[ "$tifm_file" == "/c" ]]; then echo "Cancelled." return else @@ -102,9 +115,9 @@ main() { fi ;; e) - echo "Choose a file to edit (/cancel)." + echo "Choose a file to edit (/c(ancel))." read -p "file:: " tifm_file - if [[ "$tifm_file" == "/cancel" ]]; then + if [[ "$tifm_file" == "/c" ]]; then echo "Cancelled." return else @@ -112,14 +125,14 @@ main() { fi ;; c) - echo "Choose the file and the location you would like to copy it to (/cancel)." + echo "Choose the file and the location you would like to copy it to (/c(ancel))." read -p "from:: " tifm_file_from - if [[ "$tifm_file_from" == "/cancel" ]]; then + if [[ "$tifm_file_from" == "/c" ]]; then echo "Cancelled." return fi read -p "to:: " tifm_file_to - if [[ "$tifm_file_to" == "/cancel" ]]; then + if [[ "$tifm_file_to" == "/c" ]]; then echo "Cancelled." return fi @@ -128,21 +141,21 @@ main() { m) echo "Choose the file and the new location you would like to move it to." read -p "from:: " tifm_file_from - if [[ "$tifm_file_from" == "/cancel" ]]; then + if [[ "$tifm_file_from" == "/c" ]]; then echo "Cancelled." return fi read -p "to:: " tifm_file_to - if [[ "$tifm_file_to" == "/cancel" ]]; then + if [[ "$tifm_file_to" == "/c" ]]; then echo "Cancelled." return fi mv "$tifm_file_from" "$tifm_file_to" ;; i) - echo "Choose the directory to inspect (/cancel)." + echo "Choose the directory to inspect (/c(ancel))." read -p "dir:: " tifm_dir - if [[ "$tifm_dir" == "/cancel" ]]; then + if [[ "$tifm_dir" == "/c" ]]; then echo "Cancelled." return else @@ -154,18 +167,18 @@ main() { echo "" case "$tifm_type" in d) - echo "Choose the directory you would like to create (/cancel)." + echo "Choose the directory you would like to create (/c(ancel))." read -p "name:: " tifm_dir_name - if [[ "$tifm_dir_name" == "/cancel" ]]; then + if [[ "$tifm_dir_name" == "/c" ]]; then echo "Cancelled." return fi mkdir "$tifm_dir_name" ;; f) - echo "Choose the file you would like to create (/cancel)." + echo "Choose the file you would like to create (/c(ancel))." read -p "name:: " tifm_file_name - if [[ "$tifm_file_name" == "/cancel" ]]; then + if [[ "$tifm_file_name" == "/c" ]]; then echo "Cancelled." return fi @@ -181,18 +194,18 @@ main() { echo "" case "$tifm_type" in d) - echo "Choose the directory you would like to remove (/cancel)." + echo "Choose the directory you would like to remove (/c(ancel))." read -p "name:: " tifm_dir_name - if [[ "$tifm_dir_name" == "/cancel" ]]; then + if [[ "$tifm_dir_name" == "/c" ]]; then echo "Cancelled." return fi rm -rf "$tifm_dir_name" ;; f) - echo "Choose the file you would like to remove (/cancel)." + echo "Choose the file you would like to remove (/c(ancel))." read -p "name:: " tifm_file_name - if [[ "$tifm_file_name" == "/cancel" ]]; then + if [[ "$tifm_file_name" == "/c" ]]; then echo "Cancelled." return fi @@ -204,15 +217,15 @@ main() { esac ;; P) - echo "Choose a file or folder to change the permission (/cancel)." + echo "Choose a file or folder to change the permission (/c(ancel))." read -p "item:: " tifm_select - if [[ "$tifm_select" == "/cancel" ]]; then + if [[ "$tifm_select" == "/c" ]]; then echo "Cancelled." return fi - echo "Choose the arguments from 'chmod' to set as permission for the file or folder (/cancel). (Read the manual for chmod for more info)" + echo "Choose the arguments from 'chmod' to set as permission for the file or folder (/c(ancel)). (Read the manual for chmod for more info)" read -p "perm:: " tifm_perm - if [[ "$tifm_perm" == "/cancel" ]]; then + if [[ "$tifm_perm" == "/c" ]]; then echo "Cancelled." return fi @@ -235,12 +248,12 @@ p - View file (uses 'less' by default - change in config.sh) e - edit a file (uses 'nano' by default - change in config.sh) m - Moves/Renames a file c - Copies a file to a location -i - Shows the list of files inside the directory (with detail) +i - Inspects a directory (ls -l) and pipes it to the selected pager ('less' by default - change in config.sh) n(f/d) - Creates a folder or file r(f/d) - Removes a folder or file P - Sets permissions for a specific file or folder t - Switches to command line mode, run 'exit' to exit. -; - Open config file +; - Open config file Q - Quits the program" ;; Q) From 4a108efe89defc589e75618d092369ad759329d4 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:40:39 +0200 Subject: [PATCH 13/39] quick gitignore update cause i'm testing extensions --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5a23c80..10059c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -extensions/hello.sh \ No newline at end of file +extensions/hello.sh +extensions/clock.sh \ No newline at end of file From 883fa984d1e5bc5875340ae3dc5f12e9bd8598b3 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:42:12 +0200 Subject: [PATCH 14/39] git extension update --- extensions/git.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/extensions/git.sh b/extensions/git.sh index 4c442ab..1266e3d 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -77,9 +77,24 @@ git_commit() { read -p "Commit message: " message git commit -m "$message" } +git_diff() { + # show diff between current and previous commit + git diff +} +git_log() { + # show log of all commits + git log +} +git_log_last() { + # show log of last commit + git log -1 +} tifmx.add_long G # for global git commands tifmx.bind_sub G p git_pull tifmx.bind_sub G P git_push tifmx.bind_sub G s git_status tifmx.bind_sub G a git_add -tifmx.bind_sub G c git_commit \ No newline at end of file +tifmx.bind_sub G c git_commit +tifmx.bind_sub G d git_diff +tifmx.bind_sub G l git_log +tifmx.bind_sub G L git_log_last \ No newline at end of file From 01cfd72b7f1cefce418d9ec1dac27ce65e197915 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:51:57 +0200 Subject: [PATCH 15/39] more events --- main.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/main.sh b/main.sh index 0c065ed..af67720 100644 --- a/main.sh +++ b/main.sh @@ -86,10 +86,10 @@ main() { return else cd $tifm_dir - # for ever extension, if it has a function called name.nav, call it + # for every extension, if it has a function called name.nav, call it for ext_name in "${tifm_extensions[@]}"; do if type "$ext_name".nav &> /dev/null; then - "$ext_name".nav + "$ext_name".nav "$tifm_dir" fi done fi @@ -123,6 +123,12 @@ main() { else $__TIFM_EDITOR $tifm_file fi + # for every extension, if it has a function called name.edit, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".edit &> /dev/null; then + "$ext_name".edit "$tifm_file" + fi + done ;; c) echo "Choose the file and the location you would like to copy it to (/c(ancel))." @@ -137,6 +143,12 @@ main() { return fi cp "$tifm_file_from" "$tifm_file_to" + # for every extension, if it has a function called name.copy, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".copy &> /dev/null; then + "$ext_name".copy "$tifm_file_from" "$tifm_file_to" + fi + done ;; m) echo "Choose the file and the new location you would like to move it to." @@ -151,6 +163,12 @@ main() { return fi mv "$tifm_file_from" "$tifm_file_to" + # for every extension, if it has a function called name.move, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".move &> /dev/null; then + "$ext_name".move "$tifm_file_from" "$tifm_file_to" + fi + done ;; i) echo "Choose the directory to inspect (/c(ancel))." @@ -159,7 +177,7 @@ main() { echo "Cancelled." return else - ls -l $tifm_dir + ls -l $tifm_dir | $__TIFM_PAGER fi ;; n) @@ -174,6 +192,12 @@ main() { return fi mkdir "$tifm_dir_name" + # for every extension, if it has a function called name.mkdir, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".mkdir &> /dev/null; then + "$ext_name".mkdir "$tifm_dir_name" + fi + done ;; f) echo "Choose the file you would like to create (/c(ancel))." @@ -183,6 +207,12 @@ main() { return fi touch "$tifm_file_name" + # for every extension, if it has a function called name.mkfile, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".mkfile &> /dev/null; then + "$ext_name".mkfile "$tifm_file_name" + fi + done ;; *) echo "Invalid type ([d]irectory/[f]ile)." @@ -201,6 +231,12 @@ main() { return fi rm -rf "$tifm_dir_name" + # for every extension, if it has a function called name.rmdir, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".rmdir &> /dev/null; then + "$ext_name".rmdir "$tifm_dir_name" + fi + done ;; f) echo "Choose the file you would like to remove (/c(ancel))." @@ -210,6 +246,12 @@ main() { return fi rm "$tifm_file_name" + # for every extension, if it has a function called name.rmfile, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".rmfile &> /dev/null; then + "$ext_name".rmfile "$tifm_file_name" + fi + done ;; *) echo "Invalid type ([d]irectory/[f]ile)." @@ -230,6 +272,12 @@ main() { return fi chmod $tifm_perm $tifm_select + # for every extension, if it has a function called name.fperms, call it + for ext_name in "${tifm_extensions[@]}"; do + if type "$ext_name".fperms &> /dev/null; then + "$ext_name".fperms "$tifm_select" "$tifm_perm" + fi + done ;; t) /bin/bash From 1e86a614513d548a578010f9d841d995238d6586 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 17 Aug 2022 17:30:38 +0200 Subject: [PATCH 16/39] this commit was made using the G* command of git.sh --- extensions/git.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/extensions/git.sh b/extensions/git.sh index 1266e3d..29d152b 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -89,6 +89,12 @@ git_log_last() { # show log of last commit git log -1 } +git_full() { # pull, add, commit, push + git_pull + git_add + git_commit + git_push +} tifmx.add_long G # for global git commands tifmx.bind_sub G p git_pull tifmx.bind_sub G P git_push @@ -97,4 +103,5 @@ tifmx.bind_sub G a git_add tifmx.bind_sub G c git_commit tifmx.bind_sub G d git_diff tifmx.bind_sub G l git_log -tifmx.bind_sub G L git_log_last \ No newline at end of file +tifmx.bind_sub G L git_log_last +tifmx.bind_sub G "*" git_full \ No newline at end of file From b1b0c3a226585b9a916625627de72cfd373d9b97 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 17 Aug 2022 17:58:06 +0200 Subject: [PATCH 17/39] docs 'n' tweaking --- extensions/README.md | 111 +++++++++++++++++++++++++++++++++++++++++++ main.sh | 2 +- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 extensions/README.md diff --git a/extensions/README.md b/extensions/README.md new file mode 100644 index 0000000..0862d8c --- /dev/null +++ b/extensions/README.md @@ -0,0 +1,111 @@ +# tifmx - extend tifm to your liking +we call the extension framework bundled with tifm, `tifmx`, short for `tiny file manager extensions` (creative naming!). + +tifmx automatically loads extensions placed in the `extensions` folder, allowing you to drop in extensions to add them in. + +it also provides a couple of functions for tifm to adapt its behaviour to your extension. + +## guide +here we will create a very simple greeter extension to show you how easy it is to write an extension for tifm. + +### init event +we'll start by creating a `greeter.sh` file in the `extensions` folder.
+then, we'll listen for the `init` event which is called when the extension is loaded.
+events are function definitions of this format: `ext_name.event_name`. tifmx automatically figures out the extension's name by reading the file name, so we will create our init event like this: +```bash +greeter.init() { + # code here +} +``` +then, we will simply print "Hello, $USERNAME!" to the console: +```bash +greeter.init() { + echo "Hello, $USERNAME!" +} +``` +you can test it out by launching tifm now. + +### simple command +simple commands are when you press a key and a function gets executed. we'll bind our `h` key to say `Hey all!` when it is pressed. + +we'll first start by defining our function. it can be named anything, because we will bind it using its name later; we'll call it `greet_all`: +```sh +greeter.init() { + echo "Hello, $USERNAME!" +} + +# NEW +greet_all() { + echo "Hey all!" +} +``` +awesome. but now, if you reload tifm and press the `h` key, you will get an error. this is because we haven't told tifm to listen to the key. + +we will need to use the `tifmx.bind` command to create a binding and link it to our function. you create a binding this way: +```sh +tifmx.bind char func +``` +so to bind our new `greet_all` function to the `h` key: +```sh +tifmx.bind h greet_all +``` +now your file should look like this: +```sh +greeter.init() { + echo "Hello, $USERNAME!" +} + +greet_all() { + echo "Hey all!" +} +# NEW +tifmx.bind h greet_all +``` +you can now reload tifm and press `h` to see a nice greeting! + +### long command +long commands are when you press a key to access a group, and then press another key to run a sub command. examples include `rd` (remove directory) and `nf` (new file). + +we'll make two commands: `gu` to greet the user and `gw` to greet the world. we can do this using the `tifmx.add_long` and `tifmx.bind_sub` commands. you create a binding this way: +```sh +tifmx.add_long char1 +tifmx.bind_sub char1 char2 func +# you can add infinite subcommands to a group +``` +we have already defined a function that greets the user: `greeter.init`, so in our case we can use it. but we'll create a greet world function first: +```sh +greeter.init() { + echo "Hello, $USERNAME!" +} + +greet_all() { + echo "Hey all!" +} +tifmx.bind h greet_all + +# NEW +greet_world() { + echo "Hello, world!" +} +``` + +and now we'll create our long command: +```sh +greeter.init() { + echo "Hello, $USERNAME!" +} + +greet_all() { + echo "Hey all!" +} +tifmx.bind h greet_all + +greet_world() { + echo "Hello, world!" +} +# NEW +tifmx.add_long g +tifmx.bind_sub g u greeter.init +tifmx.bind_sub g w greet_world +``` +you can now reload and test your long command out! \ No newline at end of file diff --git a/main.sh b/main.sh index af67720..1c3537e 100644 --- a/main.sh +++ b/main.sh @@ -48,7 +48,7 @@ load_extensions() { local count=0 # check how many files are in the extensions directory local files=$(ls -1 "$SCRIPT_DIR/extensions" | wc -l) - for extension in "$SCRIPT_DIR/extensions/"*; do + for extension in "$SCRIPT_DIR/extensions/"*.sh; do source "$extension" # add only the name of the extension to the array (ex: extensions/git.sh -> git) local ext_name=$(basename "$extension" | cut -d. -f1) From a4877408d771b6cf37f1f91ec23bf87ceb4c6895 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:22:27 +0200 Subject: [PATCH 18/39] docs for events --- extensions/README.md | 59 +++++++++++++++++++++++++++++++++++++++++++- main.sh | 2 +- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/extensions/README.md b/extensions/README.md index 0862d8c..43d5bb1 100644 --- a/extensions/README.md +++ b/extensions/README.md @@ -108,4 +108,61 @@ tifmx.add_long g tifmx.bind_sub g u greeter.init tifmx.bind_sub g w greet_world ``` -you can now reload and test your long command out! \ No newline at end of file +you can now reload and test your long command out! + +## documentation +### events +> **Note:** parameters are passed without name and are accessible via `$1`, `$2` and so on, or `"${@[n]}"` where `n` is a number. +#### `extension.init()` +called when your extension is loaded. + +#### `extension.nav(directory)` +called when the user changes directories, at the very end of the `N` command. + +parameters: +* `directory`: the directory the user travelled to + +#### `extension.edit(file)` +called when the user edits a file, at the very end of the `e` command. + +parameters: +* `file`: the file the user edited + +#### `extension.copy(from, to)` +called when the user copies a file, at the very end of the `c` command. + +parameters: +* `from`: the file the user copied +* `to`: the location the file was copied to + +#### `extension.move(from, to)` +called when the user moves a file, at the very end of the `m` command. + +parameters: +* `from`: the file the user moved +* `to`: the location the file was moved to + +#### `extension.mkdir(dir)` / `extension.mkfile(file)` +called when the user creates a directory/file, at the very end of the `n(d/f)` command. + +parameters (`mkdir`): +* `dir`: the directory the user created + +parameters (`mkfile`): +* `file`: the file the user created + +#### `extension.rmdir(dir)` / `extension.rmfile(file)` +called when the user deletes a directory/file, at the very end of the `r(d/f)` command. + +parameters (`rmdir`): +* `dir`: the directory the user deleted + +parameters (`rmfile`): +* `file`: the file the user deleted + +#### `extension.fperms(item, permissions)` +called when the user changes the permissions of a file, at the very end of the `P` command. + +parameters: +* `item`: the file or directory for which the permissions were modified +* `permissions`: the permission arguments given to the file (in chmod format) diff --git a/main.sh b/main.sh index 1c3537e..d0cfb50 100644 --- a/main.sh +++ b/main.sh @@ -48,7 +48,7 @@ load_extensions() { local count=0 # check how many files are in the extensions directory local files=$(ls -1 "$SCRIPT_DIR/extensions" | wc -l) - for extension in "$SCRIPT_DIR/extensions/"*.sh; do + for extension in "$SCRIPT_DIR/extensions/"*".sh"; do source "$extension" # add only the name of the extension to the array (ex: extensions/git.sh -> git) local ext_name=$(basename "$extension" | cut -d. -f1) From 264caf007975a1d56063b61f1ec95fec29887966 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:24:39 +0200 Subject: [PATCH 19/39] tweaks to help command --- main.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.sh b/main.sh index d0cfb50..b2b7051 100644 --- a/main.sh +++ b/main.sh @@ -297,8 +297,8 @@ e - edit a file (uses 'nano' by default - change in config.sh) m - Moves/Renames a file c - Copies a file to a location i - Inspects a directory (ls -l) and pipes it to the selected pager ('less' by default - change in config.sh) -n(f/d) - Creates a folder or file -r(f/d) - Removes a folder or file +n(f/d) - Creates a file or directory +r(f/d) - Removes a file or directory P - Sets permissions for a specific file or folder t - Switches to command line mode, run 'exit' to exit. ; - Open config file From 7b4e7bf583d0edc94ce45579e05058ead268a53e Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:29:09 +0200 Subject: [PATCH 20/39] editing git extension --- extensions/git.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/extensions/git.sh b/extensions/git.sh index 29d152b..d1684b5 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -25,13 +25,13 @@ git.display() { if $__tifmgit_in_repo; then local branch=$(git rev-parse --abbrev-ref HEAD) local gstatus=$(git status --porcelain) - # replace newlines with , - gstatus=$(echo "$gstatus" | tr '\n' ',') # remove leading and trailing spaces gstatus=$(echo "$gstatus" | sed 's/^ *//g;s/ *$//g') - # remove trailing , - gstatus=$(echo "$gstatus" | sed 's/,$//g') - echo "$BRIGHT$YELLOW(git branch $branch - status: $gstatus)$NORMAL" + # remove leading and trailing newlines + gstatus=$(echo "$gstatus" | sed 's/^\n//g;s/\n$//g') + # replace with count + gstatus=$(echo "$gstatus" | wc -l) + echo "$BRIGHT$YELLOW(git branch $branch - status: $gstatus modif(s))$NORMAL" fi } @@ -65,6 +65,10 @@ git_status() { gstatus=$(echo "$gstatus" | sed "s/ ? /${MAGENTA}?${NORMAL} /g") # ! file -> ${CYAN}!${NORMAL}file gstatus=$(echo "$gstatus" | sed "s/ ! /${CYAN}!${NORMAL} /g") + # if gstatus is empty, replace it with "nothing to commit" + if [ -z "$gstatus" ]; then + gstatus="nothing to commit" + fi echo -e "$BRIGHT${YELLOW}git branch $branch$NORMAL\n$gstatus" fi } From 35de3f5aaa6f3c2d67ed6b2ffe82c0531726cfe1 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 13:34:58 +0200 Subject: [PATCH 21/39] quick git.sh update --- extensions/git.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/git.sh b/extensions/git.sh index d1684b5..c1ab2b1 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -31,7 +31,12 @@ git.display() { gstatus=$(echo "$gstatus" | sed 's/^\n//g;s/\n$//g') # replace with count gstatus=$(echo "$gstatus" | wc -l) - echo "$BRIGHT$YELLOW(git branch $branch - status: $gstatus modif(s))$NORMAL" + local modif="modif" + # if modif > 1, replace with "modifs" + if [[ "$gstatus" -gt 1 ]]; then + modif="modifs" + fi + echo "$BRIGHT$YELLOW(git branch $branch - status: $gstatus $modif)$NORMAL" fi } From b335ba1be453d7de0c90a033e885b892bb6b5962 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 13:52:43 +0200 Subject: [PATCH 22/39] docs --- extensions/README.md => EXTENSIONS.md | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) rename extensions/README.md => EXTENSIONS.md (74%) diff --git a/extensions/README.md b/EXTENSIONS.md similarity index 74% rename from extensions/README.md rename to EXTENSIONS.md index 43d5bb1..537133c 100644 --- a/extensions/README.md +++ b/EXTENSIONS.md @@ -111,11 +111,25 @@ tifmx.bind_sub g w greet_world you can now reload and test your long command out! ## documentation +extensions have access to everything defined in the configuration file and pretty much every aspect of tifm. ### events +events are functions defined in your extension that get called when a specific action happens inside of tifm. you define them this way: `extension.event` where extension is the name of your extension file (without `.sh`) and `event` is the name of your event. see below for all available events. > **Note:** parameters are passed without name and are accessible via `$1`, `$2` and so on, or `"${@[n]}"` where `n` is a number. #### `extension.init()` called when your extension is loaded. +#### `extension.display()` (provided you're using the default `__TIFM_DISPLAY` in `config.sh`) +called when the display (top part of the command input) is displayed. whatever it echoes last will be added as a widget in the display. + +example: quick clock extension: +```sh +# file: extensions/clock.sh +clock.display() { + # display clock + echo -e "$CYAN$(date +"%H:%M")$NORMAL" +} +``` + #### `extension.nav(directory)` called when the user changes directories, at the very end of the `N` command. @@ -166,3 +180,33 @@ called when the user changes the permissions of a file, at the very end of the ` parameters: * `item`: the file or directory for which the permissions were modified * `permissions`: the permission arguments given to the file (in chmod format) + +### functions +you have access to multiple functions that change the behaviour of tifm. +#### `tifmx.bind(char, func)` +tells tifm to listen to when `char` is pressed, and in that case call `func`. +example: +```sh +go_home() { # navigate to the home directory + cd ~ +} +tifmx.bind "~" go_home +``` + +#### `tifmx.add_long(char)` +tells tifm to listen to when `char` is pressed, and in that case wait for another keypress and find a command associated to that combination. must be used with `tifmx.bind_sub(char1, char2, func)`. + +#### `tifmx.bind_sub(char1, char2, func)` +tells tifmx to associate the combination `char1 + char2` to call `func`. +example: +```sh +go_home() { + cd ~ +} +go_parent() { + cd .. +} +tifmx.add_long "~" +tifmx.bind_sub "~" "~" go_home # pressing ~ then ~ will return home +tifmx.bind_sub "~" "<" go_parent # pressing ~ then < will return to the parent directory +``` \ No newline at end of file From c4876bd11e8757c2aa2cfaedd04b88a831f6fe86 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 14:00:20 +0200 Subject: [PATCH 23/39] can now view git remote in git extension --- extensions/git.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/git.sh b/extensions/git.sh index c1ab2b1..95395c6 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -104,6 +104,9 @@ git_full() { # pull, add, commit, push git_commit git_push } +git_view_remote() { + git remote -v +} tifmx.add_long G # for global git commands tifmx.bind_sub G p git_pull tifmx.bind_sub G P git_push @@ -113,4 +116,5 @@ tifmx.bind_sub G c git_commit tifmx.bind_sub G d git_diff tifmx.bind_sub G l git_log tifmx.bind_sub G L git_log_last -tifmx.bind_sub G "*" git_full \ No newline at end of file +tifmx.bind_sub G "*" git_full +tifmx.bind_sub G r git_view_remote \ No newline at end of file From d95dce38559cc65740aacd6e82552734091983ca Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:11:12 +0200 Subject: [PATCH 24/39] changed `;` command and added extension manager --- config.sh | 4 +-- extension_ignore | 0 main.sh | 76 +++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 extension_ignore diff --git a/config.sh b/config.sh index ca7d7a7..ea88a6e 100644 --- a/config.sh +++ b/config.sh @@ -9,9 +9,9 @@ __TIFM_DECO_COLOUR="$CYAN" __TIFM_DISPLAY() { local stat="" if [ "$STATUS" == "0" ]; then - stat="${GREEN}✓$NORMAL" + stat="${GREEN}✔$NORMAL" else - stat="${RED}× $STATUS$NORMAL" + stat="${RED}✘ $STATUS$NORMAL" fi local string="$GREEN$BRIGHT$PWD$NORMAL $stat " # for each extension, if it has a display function, call it diff --git a/extension_ignore b/extension_ignore new file mode 100644 index 0000000..e69de29 diff --git a/main.sh b/main.sh index b2b7051..523b0e5 100644 --- a/main.sh +++ b/main.sh @@ -49,9 +49,13 @@ load_extensions() { # check how many files are in the extensions directory local files=$(ls -1 "$SCRIPT_DIR/extensions" | wc -l) for extension in "$SCRIPT_DIR/extensions/"*".sh"; do + local ext_name=$(basename "$extension" | cut -d. -f1) + # if the name is in the extension_ignore file, skip it + if grep -q "$ext_name" "$SCRIPT_DIR/extension_ignore"; then + continue + fi source "$extension" # add only the name of the extension to the array (ex: extensions/git.sh -> git) - local ext_name=$(basename "$extension" | cut -d. -f1) tifm_extensions+=("$ext_name") count=$((count + 1)) # percentage of completion @@ -72,7 +76,7 @@ main() { done < <(ls -a) read -n 1 -p "$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT $(__TIFM_PROMPT) $YELLOW" ans - if [[ "$ans" != "n" ]] && [[ "$ans" != "r" ]] && [[ ! "${tifm_extensions_longcommands[*]}" =~ "$ans" ]]; then + if [[ "$ans" != "n" ]] && [[ "$ans" != "r" ]] && [[ "$ans" != ";" ]] && [[ ! "${tifm_extensions_longcommands[*]}" =~ "$ans" ]]; then echo "" fi printf "$NORMAL" @@ -283,10 +287,68 @@ main() { /bin/bash ;; ";") - # open config - $__TIFM_EDITOR "$SCRIPT_DIR/config.sh" - # reload config - source "$SCRIPT_DIR/config.sh" + read -n 1 tifm_sub + echo "" + case "$tifm_sub" in + c) + # open config + $__TIFM_EDITOR "$SCRIPT_DIR/config.sh" + # reload config + source "$SCRIPT_DIR/config.sh" + ;; + e) + # open extension menu + local all_extensions=() + for extension in "$SCRIPT_DIR/extensions/"*".sh"; do + local ext_name=$(basename "$extension" .sh) + # if the extension name is in the extension_ignore file, ignore it + all_extensions+=("$ext_name") + done + display_extensions() { + clear + # display all extensions + echo "Extensions:" + for extension in "${all_extensions[@]}"; do + # if not in the ignored extensions list, display with a green checkmark + local grepped=$(grep "$extension" "$SCRIPT_DIR/extension_ignore") + if [[ -z "$grepped" ]]; then + echo -e " $GREEN✔$NORMAL $extension" + else + echo -e " $RED✘$NORMAL $extension" + fi + done + } + local executing=true + while $executing; do + display_extensions + echo "" + echo "type the name of an extension to toggle it, or type 'q' to quit." + read -p "extension:: " tifm_extension + if [[ "$tifm_extension" == "q" ]]; then + executing=false + continue + fi + # if the extension is ignored, unignore it + if [[ -n $(grep "$tifm_extension" "$SCRIPT_DIR/extension_ignore") ]]; then + sed -i "/$tifm_extension/d" "$SCRIPT_DIR/extension_ignore" + # remove from the ignored extensions list + local index=0 + for ext in "${ignored_extensions[@]}"; do + if [[ "$ext" == "$tifm_extension" ]]; then + unset ignored_extensions[$index] + fi + ((index++)) + done + else + # if the extension is not ignored, ignore it + echo "$tifm_extension" >> "$SCRIPT_DIR/extension_ignore" + fi + done + ;; + *) + echo "Invalid subcommand." + ;; + esac ;; "?") echo "${LIME_YELLOW}List of commands:$NORMAL @@ -301,7 +363,7 @@ n(f/d) - Creates a file or directory r(f/d) - Removes a file or directory P - Sets permissions for a specific file or folder t - Switches to command line mode, run 'exit' to exit. -; - Open config file +;(c/e) - Open [c]onfig file, [e]xtension menu Q - Quits the program" ;; Q) From 32f33a4f474d96a1999010b996d3f582d96742cf Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:16:20 +0200 Subject: [PATCH 25/39] quick fix --- extensions/git.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/git.sh b/extensions/git.sh index 95395c6..287dc62 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -29,8 +29,12 @@ git.display() { gstatus=$(echo "$gstatus" | sed 's/^ *//g;s/ *$//g') # remove leading and trailing newlines gstatus=$(echo "$gstatus" | sed 's/^\n//g;s/\n$//g') - # replace with count - gstatus=$(echo "$gstatus" | wc -l) + if [[ -z "$gstatus" ]]; then + gstatus=0 + else + # replace with count + gstatus=$(echo "$gstatus" | wc -l) + fi local modif="modif" # if modif > 1, replace with "modifs" if [[ "$gstatus" -gt 1 ]]; then From d30e261100bafe67acf0a2c0344759463d1125c3 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 18:56:30 +0200 Subject: [PATCH 26/39] extensions can now use helpstrings --- extensions/git.sh | 3 ++- main.sh | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/extensions/git.sh b/extensions/git.sh index 287dc62..f2b6238 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -121,4 +121,5 @@ tifmx.bind_sub G d git_diff tifmx.bind_sub G l git_log tifmx.bind_sub G L git_log_last tifmx.bind_sub G "*" git_full -tifmx.bind_sub G r git_view_remote \ No newline at end of file +tifmx.bind_sub G r git_view_remote +tifmx.add_help G "git commands integration ([p]ull, [P]ush, [s]tatus, [a]dd, [c]ommit, [d]iff, [l]og, [L]og last, [*]full, [r]emote)" \ No newline at end of file diff --git a/main.sh b/main.sh index 523b0e5..8561faf 100644 --- a/main.sh +++ b/main.sh @@ -1,6 +1,8 @@ #!/bin/env bash declare -a -x tifm_extensions declare -A -x tifm_extensions_commands +declare -a -x tifm_extensions_commands_list +declare -A -x tifm_extensions_commands_help declare -a -x tifm_extensions_longcommands declare -A -x tifm_extensions_subcommands tifmx.bind() { @@ -12,6 +14,10 @@ tifmx.add_long() { tifmx.bind_sub() { tifm_extensions_subcommands["$1$2"]="$3" } +tifmx.add_help() { + tifm_extensions_commands_list+=("$1") + tifm_extensions_commands_help["$1"]="$2" +} # consts __TIFM_VERSION="0.2.0" BLACK=$(tput setaf 0) @@ -351,7 +357,7 @@ main() { esac ;; "?") - echo "${LIME_YELLOW}List of commands:$NORMAL + echo "${LIME_YELLOW}List of native commands:$NORMAL N - Goes to a folder o - Opens a file p - View file (uses 'less' by default - change in config.sh) @@ -365,6 +371,10 @@ P - Sets permissions for a specific file or folder t - Switches to command line mode, run 'exit' to exit. ;(c/e) - Open [c]onfig file, [e]xtension menu Q - Quits the program" + echo "${LIME_YELLOW}List of commands defined by extensions [${tifm_extensions[@]}]:$NORMAL" + for cmd in "${tifm_extensions_commands_list[@]}"; do + echo "$cmd - ${tifm_extensions_commands_help[$cmd]}" + done ;; Q) clear From f8833354bd547c96955ee83ecea00c697dfe2d72 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 18:57:24 +0200 Subject: [PATCH 27/39] treated case for when no extensions are loaded --- main.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.sh b/main.sh index 8561faf..faeb4c6 100644 --- a/main.sh +++ b/main.sh @@ -371,10 +371,12 @@ P - Sets permissions for a specific file or folder t - Switches to command line mode, run 'exit' to exit. ;(c/e) - Open [c]onfig file, [e]xtension menu Q - Quits the program" - echo "${LIME_YELLOW}List of commands defined by extensions [${tifm_extensions[@]}]:$NORMAL" - for cmd in "${tifm_extensions_commands_list[@]}"; do - echo "$cmd - ${tifm_extensions_commands_help[$cmd]}" - done + if [[ ! -z "${tifm_extensions[@]}" ]]; then + echo "${LIME_YELLOW}List of commands defined by extensions [${tifm_extensions[@]}]:$NORMAL" + for cmd in "${tifm_extensions_commands_list[@]}"; do + echo "$cmd - ${tifm_extensions_commands_help[$cmd]}" + done + fi ;; Q) clear From e2f02ffb67c7a49341f42b0fa184303e1c4f6b4f Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:02:38 +0200 Subject: [PATCH 28/39] added case for when the command is empty --- main.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.sh b/main.sh index faeb4c6..c6351da 100644 --- a/main.sh +++ b/main.sh @@ -382,6 +382,9 @@ Q - Quits the program" clear exit ;; + "") + # do nothing + ;; *) if [[ ! -z "${tifm_extensions_commands[$ans]}" ]]; then eval "${tifm_extensions_commands[$ans]}" From 29491d17db42fd4779241b111f4290f96a8dde08 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:04:23 +0200 Subject: [PATCH 29/39] added save folder --- main.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.sh b/main.sh index c6351da..e991fad 100644 --- a/main.sh +++ b/main.sh @@ -55,6 +55,10 @@ load_extensions() { # check how many files are in the extensions directory local files=$(ls -1 "$SCRIPT_DIR/extensions" | wc -l) for extension in "$SCRIPT_DIR/extensions/"*".sh"; do + # if there is no save folder, create it + if [ ! -d "$SCRIPT_DIR/save" ]; then + mkdir "$SCRIPT_DIR/save" + fi local ext_name=$(basename "$extension" | cut -d. -f1) # if the name is in the extension_ignore file, skip it if grep -q "$ext_name" "$SCRIPT_DIR/extension_ignore"; then From 60595fa39f098be731882501cf92be69edba6407 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:05:06 +0200 Subject: [PATCH 30/39] ok you may now use the clock extension --- .gitignore | 2 -- extensions/clock.sh | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 extensions/clock.sh diff --git a/.gitignore b/.gitignore index 10059c6..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +0,0 @@ -extensions/hello.sh -extensions/clock.sh \ No newline at end of file diff --git a/extensions/clock.sh b/extensions/clock.sh new file mode 100644 index 0000000..ae414f6 --- /dev/null +++ b/extensions/clock.sh @@ -0,0 +1,4 @@ +clock.display() { + # display clock + echo -e "$CYAN$(date +"%H:%M")$NORMAL" +} \ No newline at end of file From 839e218e25c9f3431711fc57125781ef76a26198 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:14:35 +0200 Subject: [PATCH 31/39] install script draft, will test it later --- installer.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 installer.sh diff --git a/installer.sh b/installer.sh new file mode 100644 index 0000000..14d5f56 --- /dev/null +++ b/installer.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# TIFM installer script +# run by using {curl -sL https://raw.githubusercontent.com/Rexxt/tifm/master/installer.sh | bash} + +# make sure git is installed +if ! type git &> /dev/null; then + echo "git is not installed" + exit 1 +fi +# make sure we're in sudo +if [ "$EUID" -ne 0 ]; then + echo "please run as root" + exit 1 +fi + +# clone repository +git clone "https://github.com/Rexxt/tifm.git" +# remove installer.sh +rm installer.sh +mv tifm ~/tifm +echo "where should we install tifm?" +echo "1) /usr/local/bin" +echo "2) /usr/bin" +read -p "> " -n 1 -r reply +echo +case "$reply" in + 1) + echo "installing to /usr/local/bin" + echo "chmod +x ~/tifm/main.sh; ~/tifm/main.sh" /usr/local/bin/tifm + chmod +x /usr/local/bin/tifm + ;; + 2) + echo "installing to /usr/bin" + echo "chmod +x ~/tifm/main.sh; ~/tifm/main.sh" /usr/bin/tifm + chmod +x /usr/bin/tifm + ;; + *) + echo "invalid option" + exit 1 + ;; +esac \ No newline at end of file From 4415c88fba281286fd4b17ec994e6eaef4ba7edd Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:20:29 +0200 Subject: [PATCH 32/39] docs --- EXTENSIONS.md | 13 +++++++++++++ installer.sh | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/EXTENSIONS.md b/EXTENSIONS.md index 537133c..4a7f978 100644 --- a/EXTENSIONS.md +++ b/EXTENSIONS.md @@ -209,4 +209,17 @@ go_parent() { tifmx.add_long "~" tifmx.bind_sub "~" "~" go_home # pressing ~ then ~ will return home tifmx.bind_sub "~" "<" go_parent # pressing ~ then < will return to the parent directory +``` + +#### `tifmx.add_help(char, helpstring)` +adds a custom line in the `?` command to show the usage of your custom command. +example: +```sh +go_home() { + cd ~ +} +tifmx.bind "~" go_home +tifmx.add_help "~" "return to the parent directory" +# will show like this: +# ~ - return to the parent directory ``` \ No newline at end of file diff --git a/installer.sh b/installer.sh index 14d5f56..b58434c 100644 --- a/installer.sh +++ b/installer.sh @@ -1,6 +1,6 @@ #!/bin/bash # TIFM installer script -# run by using {curl -sL https://raw.githubusercontent.com/Rexxt/tifm/master/installer.sh | bash} +# run by using {sudo curl -sL https://raw.githubusercontent.com/Rexxt/tifm/master/installer.sh | bash} # make sure git is installed if ! type git &> /dev/null; then From 0eb9202e8bb9825831a39c3a60485d21eaab9131 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:21:11 +0200 Subject: [PATCH 33/39] fix installer 1 --- installer.sh | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/installer.sh b/installer.sh index b58434c..5ee7fcc 100644 --- a/installer.sh +++ b/installer.sh @@ -8,16 +8,15 @@ if ! type git &> /dev/null; then exit 1 fi # make sure we're in sudo -if [ "$EUID" -ne 0 ]; then - echo "please run as root" - exit 1 -fi +# if [ "$EUID" -ne 0 ]; then +# echo "please run as root" +# exit 1 +# fi -# clone repository git clone "https://github.com/Rexxt/tifm.git" -# remove installer.sh -rm installer.sh -mv tifm ~/tifm +rm tifm/installer.sh +mkdir -p ~/tifm +mv tifm ~ echo "where should we install tifm?" echo "1) /usr/local/bin" echo "2) /usr/bin" @@ -26,16 +25,25 @@ echo case "$reply" in 1) echo "installing to /usr/local/bin" - echo "chmod +x ~/tifm/main.sh; ~/tifm/main.sh" /usr/local/bin/tifm + touch /usr/local/bin/tifm + echo "chmod +x ~/tifm/main.sh; ~/tifm/main.sh" > /usr/local/bin/tifm chmod +x /usr/local/bin/tifm ;; 2) echo "installing to /usr/bin" - echo "chmod +x ~/tifm/main.sh; ~/tifm/main.sh" /usr/bin/tifm + touch /usr/bin/tifm + echo "chmod +x ~/tifm/main.sh; ~/tifm/main.sh" > /usr/bin/tifm chmod +x /usr/bin/tifm ;; *) echo "invalid option" exit 1 ;; -esac \ No newline at end of file +esac +# check if tifm command is in path +if ! type tifm &> /dev/null; then + echo "tifm is not in path... this is most likely a problem on our side." + exit 1 +else + echo "tifm is installed and usable!" +fi \ No newline at end of file From 7ea53a9f75eb900bdb389549a9cceee63d6e1313 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:21:28 +0200 Subject: [PATCH 34/39] fix installer 2 --- installer.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/installer.sh b/installer.sh index 5ee7fcc..e528910 100644 --- a/installer.sh +++ b/installer.sh @@ -8,10 +8,10 @@ if ! type git &> /dev/null; then exit 1 fi # make sure we're in sudo -# if [ "$EUID" -ne 0 ]; then -# echo "please run as root" -# exit 1 -# fi +if [ "$EUID" -ne 0 ]; then + echo "please run as root" + exit 1 +fi git clone "https://github.com/Rexxt/tifm.git" rm tifm/installer.sh From b4ca4469daa68edc18208e6f120351ca2eea00cd Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Thu, 18 Aug 2022 20:41:59 +0200 Subject: [PATCH 35/39] fix installer 3 --- installer.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/installer.sh b/installer.sh index e528910..d4b3940 100644 --- a/installer.sh +++ b/installer.sh @@ -26,13 +26,15 @@ case "$reply" in 1) echo "installing to /usr/local/bin" touch /usr/local/bin/tifm - echo "chmod +x ~/tifm/main.sh; ~/tifm/main.sh" > /usr/local/bin/tifm + echo "~/tifm/main.sh" > /usr/local/bin/tifm + chmod +x ~/tifm/main.sh chmod +x /usr/local/bin/tifm ;; 2) echo "installing to /usr/bin" touch /usr/bin/tifm - echo "chmod +x ~/tifm/main.sh; ~/tifm/main.sh" > /usr/bin/tifm + echo "~/tifm/main.sh" > /usr/bin/tifm + chmod +x ~/tifm/main.sh chmod +x /usr/bin/tifm ;; *) From 4c8aefc03e666a7e6ccfc306db42735e38c2f936 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Wed, 24 Aug 2022 13:23:01 +0200 Subject: [PATCH 36/39] oopsie --- config.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.sh b/config.sh index ea88a6e..11f3ece 100644 --- a/config.sh +++ b/config.sh @@ -24,5 +24,6 @@ __TIFM_DISPLAY() { } __TIFM_LS_COLOUR="$BLUE" __TIFM_PROMPT() { - echo "$CYAN$USERNAME>" + user=$(whoami) + echo "$CYAN$user>" } \ No newline at end of file From 16c255b647badd45fdfee2ab9b7c749c4dc048aa Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Fri, 16 Sep 2022 22:01:16 +0200 Subject: [PATCH 37/39] added GC = git commit to git extension --- extensions/git.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/git.sh b/extensions/git.sh index f2b6238..1650472 100644 --- a/extensions/git.sh +++ b/extensions/git.sh @@ -111,7 +111,12 @@ git_full() { # pull, add, commit, push git_view_remote() { git remote -v } +git_clone() { + read -p "Git URL: " url + git clone "$url" +} tifmx.add_long G # for global git commands +tifmx.bind_sub G C git_clone tifmx.bind_sub G p git_pull tifmx.bind_sub G P git_push tifmx.bind_sub G s git_status @@ -122,4 +127,4 @@ tifmx.bind_sub G l git_log tifmx.bind_sub G L git_log_last tifmx.bind_sub G "*" git_full tifmx.bind_sub G r git_view_remote -tifmx.add_help G "git commands integration ([p]ull, [P]ush, [s]tatus, [a]dd, [c]ommit, [d]iff, [l]og, [L]og last, [*]full, [r]emote)" \ No newline at end of file +tifmx.add_help G "git commands integration ([C]lone, [p]ull, [P]ush, [s]tatus, [a]dd, [c]ommit, [d]iff, [l]og, [L]og last, [*]full, [r]emote)" \ No newline at end of file From 2e32503cfadc58616bc799dcab6a62c6cc1ef802 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Fri, 7 Oct 2022 20:17:31 +0200 Subject: [PATCH 38/39] Update installer.sh --- installer.sh | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/installer.sh b/installer.sh index d4b3940..b23dcbf 100644 --- a/installer.sh +++ b/installer.sh @@ -7,11 +7,6 @@ if ! type git &> /dev/null; then echo "git is not installed" exit 1 fi -# make sure we're in sudo -if [ "$EUID" -ne 0 ]; then - echo "please run as root" - exit 1 -fi git clone "https://github.com/Rexxt/tifm.git" rm tifm/installer.sh @@ -25,17 +20,17 @@ echo case "$reply" in 1) echo "installing to /usr/local/bin" - touch /usr/local/bin/tifm + sudo touch /usr/local/bin/tifm echo "~/tifm/main.sh" > /usr/local/bin/tifm - chmod +x ~/tifm/main.sh - chmod +x /usr/local/bin/tifm + sudo chmod +x ~/tifm/main.sh + sudo chmod +x /usr/local/bin/tifm ;; 2) echo "installing to /usr/bin" - touch /usr/bin/tifm + sudo touch /usr/bin/tifm echo "~/tifm/main.sh" > /usr/bin/tifm - chmod +x ~/tifm/main.sh - chmod +x /usr/bin/tifm + sudo chmod +x ~/tifm/main.sh + sudo chmod +x /usr/bin/tifm ;; *) echo "invalid option" @@ -48,4 +43,4 @@ if ! type tifm &> /dev/null; then exit 1 else echo "tifm is installed and usable!" -fi \ No newline at end of file +fi From 2091129f4d193cedb5cbb78d96eb30076fe2ae64 Mon Sep 17 00:00:00 2001 From: Mizu <40831463+Rexxt@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:27:04 +0100 Subject: [PATCH 39/39] =?UTF-8?q?New=20features!!=1B[D=1B[D=1B[D=1B[D=1B[D?= =?UTF-8?q?=1B[D=1B[D=1B[D=1B[D=1B[D=1B[D=1B[D=1B[n=1B[C=1B[C=1B[C=1B[C=1B?= =?UTF-8?q?[C=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C?= =?UTF-8?q?=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C=1B[C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.sh | 4 ++- main.sh | 80 ++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/config.sh b/config.sh index 11f3ece..2c3d23b 100644 --- a/config.sh +++ b/config.sh @@ -6,6 +6,7 @@ __ANGLE_DOWN_RIGHT="╰" __ANGLE_DOWN_LEFT="╯" __VBAR="│" __TIFM_DECO_COLOUR="$CYAN" +__TIFM_CONFIRM_RETURN=true __TIFM_DISPLAY() { local stat="" if [ "$STATUS" == "0" ]; then @@ -22,7 +23,8 @@ __TIFM_DISPLAY() { done echo "$string" } -__TIFM_LS_COLOUR="$BLUE" +__TIFM_LS_COLOUR_FILE="$BLUE" +__TIFM_LS_COLOUR_DIRECTORY="$LIME_YELLOW" __TIFM_PROMPT() { user=$(whoami) echo "$CYAN$user>" diff --git a/main.sh b/main.sh index e991fad..576a5b4 100644 --- a/main.sh +++ b/main.sh @@ -19,7 +19,7 @@ tifmx.add_help() { tifm_extensions_commands_help["$1"]="$2" } # consts -__TIFM_VERSION="0.2.0" +__TIFM_VERSION="0.2.1" BLACK=$(tput setaf 0) RED=$(tput setaf 1) GREEN=$(tput setaf 2) @@ -82,7 +82,15 @@ load_extensions() { main() { echo "$__TIFM_DECO_COLOUR$__ANGLE_UP_RIGHT $(__TIFM_DISPLAY)$NORMAL" while read file; do - echo "$__TIFM_DECO_COLOUR$__VBAR $__TIFM_LS_COLOUR$file$NORMAL" + __color="$__TIFM_LS_COLOUR_FILE" + __post="" + __icon="🗎" + if [ -d "$file" ]; then + __color="$__TIFM_LS_COLOUR_DIRECTORY" + __post="/" + __icon="␣" + fi + echo "$__TIFM_DECO_COLOUR$__VBAR$__color $__icon $file$__post$NORMAL" done < <(ls -a) read -n 1 -p "$__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT $(__TIFM_PROMPT) $YELLOW" ans @@ -91,11 +99,12 @@ main() { fi printf "$NORMAL" + # command execution case "$ans" in N) - echo "Select a directory to go to (/c(ancel))." + echo "Select a directory to go to (leave blank to cancel)." read -p "nav:: " tifm_dir - if [[ "$tifm_dir" == "/c" ]]; then + if [[ "$tifm_dir" == "" ]]; then echo "Cancelled." return else @@ -109,9 +118,9 @@ main() { fi ;; o) - echo "Choose a file to open (/c(ancel))." + echo "Choose a file to open (leave blank to cancel)." read -p "file:: " tifm_file - if [[ "$tifm_file" == "/c" ]]; then + if [[ "$tifm_file" == "" ]]; then echo "Cancelled." return else @@ -119,9 +128,9 @@ main() { fi ;; p) - echo "Choose a file to view (/c(ancel))." + echo "Choose a file to view (leave blank to cancel)." read -p "file:: " tifm_file - if [[ "$tifm_file" == "/c" ]]; then + if [[ "$tifm_file" == "" ]]; then echo "Cancelled." return else @@ -129,9 +138,9 @@ main() { fi ;; e) - echo "Choose a file to edit (/c(ancel))." + echo "Choose a file to edit (leave blank to cancel)." read -p "file:: " tifm_file - if [[ "$tifm_file" == "/c" ]]; then + if [[ "$tifm_file" == "" ]]; then echo "Cancelled." return else @@ -145,14 +154,14 @@ main() { done ;; c) - echo "Choose the file and the location you would like to copy it to (/c(ancel))." + echo "Choose the file and the location you would like to copy it to (leave blank to cancel)." read -p "from:: " tifm_file_from - if [[ "$tifm_file_from" == "/c" ]]; then + if [[ "$tifm_file_from" == "" ]]; then echo "Cancelled." return fi read -p "to:: " tifm_file_to - if [[ "$tifm_file_to" == "/c" ]]; then + if [[ "$tifm_file_to" == "" ]]; then echo "Cancelled." return fi @@ -167,12 +176,12 @@ main() { m) echo "Choose the file and the new location you would like to move it to." read -p "from:: " tifm_file_from - if [[ "$tifm_file_from" == "/c" ]]; then + if [[ "$tifm_file_from" == "" ]]; then echo "Cancelled." return fi read -p "to:: " tifm_file_to - if [[ "$tifm_file_to" == "/c" ]]; then + if [[ "$tifm_file_to" == "" ]]; then echo "Cancelled." return fi @@ -185,9 +194,9 @@ main() { done ;; i) - echo "Choose the directory to inspect (/c(ancel))." + echo "Choose the directory to inspect (leave blank to cancel)." read -p "dir:: " tifm_dir - if [[ "$tifm_dir" == "/c" ]]; then + if [[ "$tifm_dir" == "" ]]; then echo "Cancelled." return else @@ -199,9 +208,9 @@ main() { echo "" case "$tifm_type" in d) - echo "Choose the directory you would like to create (/c(ancel))." + echo "Choose the directory you would like to create (leave blank to cancel)." read -p "name:: " tifm_dir_name - if [[ "$tifm_dir_name" == "/c" ]]; then + if [[ "$tifm_dir_name" == "" ]]; then echo "Cancelled." return fi @@ -214,9 +223,9 @@ main() { done ;; f) - echo "Choose the file you would like to create (/c(ancel))." + echo "Choose the file you would like to create (leave blank to cancel)." read -p "name:: " tifm_file_name - if [[ "$tifm_file_name" == "/c" ]]; then + if [[ "$tifm_file_name" == "" ]]; then echo "Cancelled." return fi @@ -238,9 +247,9 @@ main() { echo "" case "$tifm_type" in d) - echo "Choose the directory you would like to remove (/c(ancel))." + echo "Choose the directory you would like to remove (leave blank to cancel)." read -p "name:: " tifm_dir_name - if [[ "$tifm_dir_name" == "/c" ]]; then + if [[ "$tifm_dir_name" == "" ]]; then echo "Cancelled." return fi @@ -253,9 +262,9 @@ main() { done ;; f) - echo "Choose the file you would like to remove (/c(ancel))." + echo "Choose the file you would like to remove (leave blank to cancel)." read -p "name:: " tifm_file_name - if [[ "$tifm_file_name" == "/c" ]]; then + if [[ "$tifm_file_name" == "" ]]; then echo "Cancelled." return fi @@ -273,15 +282,15 @@ main() { esac ;; P) - echo "Choose a file or folder to change the permission (/c(ancel))." + echo "Choose a file or folder to change the permission (leave blank to cancel)." read -p "item:: " tifm_select - if [[ "$tifm_select" == "/c" ]]; then + if [[ "$tifm_select" == "" ]]; then echo "Cancelled." return fi - echo "Choose the arguments from 'chmod' to set as permission for the file or folder (/c(ancel)). (Read the manual for chmod for more info)" + echo "Choose the arguments from 'chmod' to set as permission for the file or folder (leave blank to cancel). (Read the manual for chmod for more info)" read -p "perm:: " tifm_perm - if [[ "$tifm_perm" == "/c" ]]; then + if [[ "$tifm_perm" == "" ]]; then echo "Cancelled." return fi @@ -406,7 +415,6 @@ Q - Quits the program" ;; esac STATUS=$? - echo "" } ( @@ -420,5 +428,17 @@ $__TIFM_DECO_COLOUR$__ANGLE_DOWN_RIGHT$NORMAL strike '?' for help" echo "" while true; do main + if "$__TIFM_CONFIRM_RETURN"; then + # wait for user to agree to return to the file view + echo + echo "${BRIGHT}${RED}press q to return to file view${NORMAL}" + key="" + while [ ! "$key" == "q" ]; do + read -n 1 key + done + clear + else + echo + fi done )