From 7fd81bbd903eb097d4897ea3a9d5030123ce735a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 5 Jul 2020 01:36:40 +0000 Subject: [PATCH] add bat for Windows 10 --- bat/README.md | 15 ++++++++++++--- bat/install.ps1 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 bat/install.ps1 diff --git a/bat/README.md b/bat/README.md index 232a2ac..878fda4 100644 --- a/bat/README.md +++ b/bat/README.md @@ -4,10 +4,19 @@ homepage: https://github.com/sharkdp/bat tagline: | bat: A cat(1) clone with syntax highlighting and Git integration. description: | - `bat` is pretty much what `cat` would be if it were developed today in the world of Markdown, git, etc. + `bat` is pretty much what `cat` would be if it were developed today's in the world of Markdown, git, etc. --- -## How to alias as `cat` +### How to run on Windows 10 + +On Windows 10 you'll get an error like this: + +> execution cannot proceed run because vcruntime140.dll was not found + +You need to download and install the +[Microsoft Visual C++ Redistributable](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) + +### How to alias as `cat` Update your `.bashrc`, `.zshrc`, or `.profile` @@ -15,7 +24,7 @@ Update your `.bashrc`, `.zshrc`, or `.profile` alias cat="bat --style=plain" ``` -## How to change the default behavior +### How to change the default behavior Take a look at the config options: diff --git a/bat/install.ps1 b/bat/install.ps1 new file mode 100644 index 0000000..a4acba3 --- /dev/null +++ b/bat/install.ps1 @@ -0,0 +1,44 @@ +#!/usr/bin/env pwsh + +$VERNAME = "$Env:PKG_NAME-v$Env:WEBI_VERSION.exe" +$EXENAME = "$Env:PKG_NAME.exe" +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) +{ + # TODO: arch detection + echo "Downloading $Env:PKG_NAME from $Env:WEBI_PKG_URL to $Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE.part" + & move "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE.part" "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" +} + +IF (!(Test-Path -Path "$Env:USERPROFILE\.local\xbin\$VERNAME")) +{ + echo "Installing $Env:PKG_NAME" + # TODO: temp directory + + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path "$Env:PKG_NAME-v*" -Recurse -ErrorAction Ignore + + # Unpack archive + # Windows BSD-tar handles zip. Imagine that. + echo "Unpacking $Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + & tar xf "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + # Move single binary into root of temporary folder + & move "bat.exe" "$VERNAME" + & dir + + # Settle unpacked archive into place + echo "New Name: $VERNAME" + echo "New Location: $Env:USERPROFILE\.local\xbin\$VERNAME" + Move-Item -Path "$VERNAME" -Destination "$Env:USERPROFILE\.local\xbin" + + # Exit tmp + popd +} + +echo "Copying into '$Env:USERPROFILE\.local\bin\$EXENAME' from '$Env:USERPROFILE\.local\xbin\$VERNAME'" +Remove-Item -Path "$Env:USERPROFILE\.local\bin\$EXENAME" -Recurse -ErrorAction Ignore +Copy-Item -Path "$Env:USERPROFILE\.local\xbin\$VERNAME" -Destination "$Env:USERPROFILE\.local\bin\$EXENAME" -Recurse -- 2.25.1