From 4fe94ee7da3fb953f4fe531ef64e82e53464bb54 Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sat, 17 Sep 2022 18:35:26 +0300 Subject: [PATCH 1/9] Set FavoriteEditor to null initially --- settings.json | 2 +- src/Navigatio/Commands/ChangeSettings.cs | 32 ++++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/settings.json b/settings.json index f9f19d1..8f9685a 100644 --- a/settings.json +++ b/settings.json @@ -1,4 +1,4 @@ { "CommandHistoryLimit": 100, - "FavoriteEditor": "notepad" + "FavoriteEditor": null } diff --git a/src/Navigatio/Commands/ChangeSettings.cs b/src/Navigatio/Commands/ChangeSettings.cs index 4f48856..da82b1d 100644 --- a/src/Navigatio/Commands/ChangeSettings.cs +++ b/src/Navigatio/Commands/ChangeSettings.cs @@ -9,33 +9,34 @@ public class ChangeSettings : IExecutable, ICancellable public ChangeSettings(Settings current, IStorage storage) { - OldSettings = current; + Settings = current; _storage = storage; } - public Settings OldSettings { get; set; } + public Settings Settings { get; set; } public bool Execute(params string[] _) { - Process? editor; + string editor = Settings.FavoriteEditor ?? GetDefaultEditor(); + if (Settings.FavoriteEditor is null) + { + Console.WriteLine($"Favorite editor is not specified. Falling back to {editor}."); + } + + Process? editorInstance; try { - var info = new ProcessStartInfo(OldSettings.FavoriteEditor ?? "", _storage.File) - { - Verb = "Edit" - }; - editor = Process.Start(info) ?? throw new NullReferenceException(); + var info = new ProcessStartInfo(editor, _storage.File) { Verb = "Edit" }; + editorInstance = Process.Start(info) ?? throw new NullReferenceException(); } catch { - Console.WriteLine( - $"Failed to open your favorite editor ({OldSettings.FavoriteEditor})." - ); + Console.WriteLine($"Failed to open your favorite editor ({editor})."); return false; } Console.WriteLine("Waiting for your editor to exit..."); - editor?.WaitForExit(); + editorInstance?.WaitForExit(); Console.WriteLine("Settings are changed."); return true; } @@ -45,9 +46,14 @@ public void Cancel() _storage.Load( settings => { - OldSettings.ShallowCopyTo(settings); + Settings.ShallowCopyTo(settings); Console.WriteLine("Settings are changed."); } ); } + + private string GetDefaultEditor() + { + return "notepad"; + } } From d81b08771504ec09cf205fe49dc9ca2328ce403c Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sat, 17 Sep 2022 18:45:33 +0300 Subject: [PATCH 2/9] Adjust a release.sh script --- scripts/release.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index 41d8220..8908377 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -3,10 +3,10 @@ PROJECT_DIR=src/navigatio BASE_DIR=${PROJECT_DIR}/bin/Release -rm -rf ${BASE_DIR}/x86 && \ -dotnet publish $PROJECT_DIR -c Release -o ${BASE_DIR}/x86 -a x86 --sc true && \ -powershell Compress-Archive -Path "'${BASE_DIR}/x86/*'" -DestinationPath 'windows-x86.zip' -Force +rm -rf ${BASE_DIR}/win-x86 && \ +dotnet publish $PROJECT_DIR --configuration Release --output ${BASE_DIR}/win-x86 --runtime win-x86 --self-contained true && \ +powershell Compress-Archive -Path "'${BASE_DIR}/win-x86/*'" -DestinationPath 'win-x86.zip' -Force -rm -rf ${BASE_DIR}/x64 && \ -dotnet publish $PROJECT_DIR -c Release -o ${BASE_DIR}/x64 -a x64 --sc true && \ -powershell Compress-Archive -Path "'${BASE_DIR}/x64/*'" -DestinationPath 'windows-x64.zip' -Force +rm -rf ${BASE_DIR}/win-x64 && \ +dotnet publish $PROJECT_DIR --configuration Release --output ${BASE_DIR}/win-x64 --runtime win-x64 --self-contained true && \ +powershell Compress-Archive -Path "'${BASE_DIR}/win-x64/*'" -DestinationPath 'win-x64.zip' -Force From cf0a9ccd712fc058373c08627d5906db5c67f0cc Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sat, 17 Sep 2022 18:57:39 +0300 Subject: [PATCH 3/9] Use function in the release.sh script --- scripts/release.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index 8908377..cf404d4 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -3,10 +3,13 @@ PROJECT_DIR=src/navigatio BASE_DIR=${PROJECT_DIR}/bin/Release -rm -rf ${BASE_DIR}/win-x86 && \ -dotnet publish $PROJECT_DIR --configuration Release --output ${BASE_DIR}/win-x86 --runtime win-x86 --self-contained true && \ -powershell Compress-Archive -Path "'${BASE_DIR}/win-x86/*'" -DestinationPath 'win-x86.zip' -Force +function release_for_os() { + rm -rf ${BASE_DIR}/$1 && \ -rm -rf ${BASE_DIR}/win-x64 && \ -dotnet publish $PROJECT_DIR --configuration Release --output ${BASE_DIR}/win-x64 --runtime win-x64 --self-contained true && \ -powershell Compress-Archive -Path "'${BASE_DIR}/win-x64/*'" -DestinationPath 'win-x64.zip' -Force + dotnet publish $PROJECT_DIR --configuration Release --output ${BASE_DIR}/$1 --runtime $1 --self-contained true && \ + + powershell Compress-Archive -Path "'${BASE_DIR}/$1/*'" -DestinationPath "$1.zip" -Force +} + +release_for_os win-x86 +release_for_os win-x64 From 81d916a77c01180f3f5fba6076d3ab8899317bd6 Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sat, 17 Sep 2022 19:24:33 +0300 Subject: [PATCH 4/9] Determine a default editor based on OS --- src/Navigatio/Commands/ChangeSettings.cs | 30 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Navigatio/Commands/ChangeSettings.cs b/src/Navigatio/Commands/ChangeSettings.cs index da82b1d..253166f 100644 --- a/src/Navigatio/Commands/ChangeSettings.cs +++ b/src/Navigatio/Commands/ChangeSettings.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using Navigatio.Storages; +using System.Runtime.InteropServices; namespace Navigatio.Commands; @@ -17,10 +18,22 @@ public ChangeSettings(Settings current, IStorage storage) public bool Execute(params string[] _) { - string editor = Settings.FavoriteEditor ?? GetDefaultEditor(); + string editor = ""; + try + { + editor = Settings.FavoriteEditor ?? GetDefaultEditor(); + } + catch (PlatformNotSupportedException) + { + Console.WriteLine( + $"Sorry, your OS is currently not supported. Please open file {_storage.File} and edit it manually." + ); + return false; + } + if (Settings.FavoriteEditor is null) { - Console.WriteLine($"Favorite editor is not specified. Falling back to {editor}."); + Console.WriteLine($"Note: favorite editor is not specified. Falling back to {editor}."); } Process? editorInstance; @@ -54,6 +67,17 @@ public void Cancel() private string GetDefaultEditor() { - return "notepad"; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return "vi"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return "notepad"; + } + else + { + throw new PlatformNotSupportedException(); + } } } From 29b2c502ace197f95bd2caf890fca2f8e0a6486e Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sat, 17 Sep 2022 19:39:47 +0300 Subject: [PATCH 5/9] Change name of an executable in nav.sh --- scripts/nav.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/nav.sh b/scripts/nav.sh index 6b6e79f..062d2ce 100644 --- a/scripts/nav.sh +++ b/scripts/nav.sh @@ -3,7 +3,7 @@ ROOT=$1 OUTPUT_FILE=${ROOT}output.sh -${ROOT}navigatio.exe ${OUTPUT_FILE} ${@:2} +${ROOT}Navigatio ${OUTPUT_FILE} ${@:2} if test -f ${OUTPUT_FILE}; then source ${OUTPUT_FILE} From afce4f87ac829932445edcd8be38e4307e6667a1 Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sun, 18 Sep 2022 18:02:45 +0300 Subject: [PATCH 6/9] Adjust scripts so that they work on linux --- scripts/dev-build.sh | 4 ++- scripts/nav.sh | 6 ++-- scripts/release-setup.sh | 3 -- scripts/release.sh | 3 +- scripts/setup.sh | 51 ++++++++++++++++++++++++++++------ scripts/uninstall.sh | 2 +- src/Navigatio/Navigatio.csproj | 1 - 7 files changed, 51 insertions(+), 19 deletions(-) delete mode 100644 scripts/release-setup.sh diff --git a/scripts/dev-build.sh b/scripts/dev-build.sh index dcf4854..c2c0e0d 100644 --- a/scripts/dev-build.sh +++ b/scripts/dev-build.sh @@ -1 +1,3 @@ -dotnet build src/navigatio --no-restore && source scripts/setup.sh src/navigatio/bin/debug/net6.0/ +#!/usr/bin/env bash + +dotnet build src/navigatio --no-restore && scripts/setup.sh src/navigatio/bin/debug/net6.0/ diff --git a/scripts/nav.sh b/scripts/nav.sh index 062d2ce..142f649 100644 --- a/scripts/nav.sh +++ b/scripts/nav.sh @@ -1,9 +1,9 @@ -#!/usr/bin/env +#!/usr/bin/env bash ROOT=$1 -OUTPUT_FILE=${ROOT}output.sh +OUTPUT_FILE=$2 -${ROOT}Navigatio ${OUTPUT_FILE} ${@:2} +${ROOT}/Navigatio ${OUTPUT_FILE} ${@:3} if test -f ${OUTPUT_FILE}; then source ${OUTPUT_FILE} diff --git a/scripts/release-setup.sh b/scripts/release-setup.sh deleted file mode 100644 index 12a999f..0000000 --- a/scripts/release-setup.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env - -source setup.sh ./ diff --git a/scripts/release.sh b/scripts/release.sh index cf404d4..6369ebb 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env +#!/usr/bin/env bash PROJECT_DIR=src/navigatio BASE_DIR=${PROJECT_DIR}/bin/Release @@ -13,3 +13,4 @@ function release_for_os() { release_for_os win-x86 release_for_os win-x64 +release_for_os linux-x64 diff --git a/scripts/setup.sh b/scripts/setup.sh index 01cce99..0abc19f 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,12 +1,45 @@ -#!/usr/bin/env +#!/usr/bin/env bash -ROOT=/usr/local/bin/navigatio -EXE_PATH=$1 +export ROOT=/usr/local/bin/navigatio +export EXE_PATH=$1 -mkdir -p $ROOT -cp -r ${EXE_PATH}. $ROOT -chmod +x ${ROOT}/nav.sh +function create_dir() { + mkdir -p $ROOT + cp -r ${EXE_PATH}. $ROOT +} -echo "" >> ~/.bashrc -echo "alias nav='source ${ROOT}/nav.sh ${ROOT}/'" >> ~/.bashrc -source ~/.bashrc +function sudo_create_dir() { + sudo -E bash -c "$(declare -f create_dir); create_dir" +} + +function set_permissions() { + sudo touch ${ROOT}/output.sh + sudo touch ${ROOT}/aliases.json + sudo touch ${ROOT}/history.json + + sudo chmod a+x ${ROOT}/nav.sh + sudo chmod a+x ${ROOT}/Navigatio + sudo chmod a+wx ${ROOT}/output.sh + sudo chmod a+w ${ROOT}/settings.json + sudo chmod a+w ${ROOT}/aliases.json + sudo chmod a+w ${ROOT}/history.json +} + +function create_alias() { + echo "" >> ~/.bashrc + echo "alias nav='source ${ROOT}/nav.sh ${ROOT} ${ROOT}/output.sh'" >> ~/.bashrc +} + +unamestr=$(uname) +if [[ "$unamestr" == 'Linux' ]] +then + sudo_create_dir + set_permissions +else + create_dir +fi + +create_alias + +unset ROOT +unset EXE_PATH diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 7a1ab70..c9cf298 100644 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -1,3 +1,3 @@ -#!/usr/bin/env +#!/usr/bin/env bash rm -rf /usr/local/bin/navigatio diff --git a/src/Navigatio/Navigatio.csproj b/src/Navigatio/Navigatio.csproj index e6c440e..87fe4e7 100644 --- a/src/Navigatio/Navigatio.csproj +++ b/src/Navigatio/Navigatio.csproj @@ -14,7 +14,6 @@ - From e084b88349219291b37edaedb03b6bfac5e06e65 Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sun, 18 Sep 2022 18:26:45 +0300 Subject: [PATCH 7/9] Update readme --- README.md | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b23d9c6..7ef923e 100644 --- a/README.md +++ b/README.md @@ -27,19 +27,36 @@ If you use a terminal and you need to move between directories frequently, then ## Installation -1. Download and install [git](https://git-scm.com/download/win) (you'll need a git bash in order to use the app) +### Linux + +1. Download and unpack the latest [release](https://github.com/VladBrok/navigatio/releases) for linux (file linux-x64.zip) + +2. Open the folder with unpacked files in the terminal and run the setup + +```bash +sudo chmod +x setup.sh +./setup.sh ./ +``` -2. Download and unpack the latest [release](https://github.com/VladBrok/navigatio/releases) for your specific platform +3. Restart the terminal -_By now, only Windows is supported_ +Done! Now you can run `nav -h` for a list of all available commands -3. Run the setup +### Windows + +1. Download and install [git](https://git-scm.com/download/win) (you'll need a git bash in order to use the app) + +2. Download and unpack the latest [release](https://github.com/VladBrok/navigatio/releases) for your specific architecture (win-x64.zip or win-x86.zip) + +3. Open the folder with unpacked files in the git bash and run the setup ```bash -source release-setup.sh +./setup.sh ./ ``` -Now you can run `nav -h` for a list of all available commands +4. Restart the git bash + +Done! Now you can run `nav -h` for a list of all available commands ## Usage From 6f2ca6efc9d448742265ea9b543a1b245ef78a96 Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sun, 18 Sep 2022 18:45:36 +0300 Subject: [PATCH 8/9] Add missing references to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7ef923e..5c91c69 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Fast navigation between directories - [Introduction](#introduction) - [Features](#features) - [Installation](#installation) + - [Linux](#linux) + - [Windows](#windows) - [Usage](#usage) - [License](#license) From 87abbfca03a06b28d592b24986b4fc6f240715a8 Mon Sep 17 00:00:00 2001 From: Vlad Brok Date: Sun, 18 Sep 2022 19:07:12 +0300 Subject: [PATCH 9/9] Fix a setup command for Linux --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c91c69..edd6fde 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,7 @@ If you use a terminal and you need to move between directories frequently, then 2. Open the folder with unpacked files in the terminal and run the setup ```bash -sudo chmod +x setup.sh -./setup.sh ./ +sudo chmod +x setup.sh && ./setup.sh ./ ``` 3. Restart the terminal