diff --git a/package.json b/package.json index 3840255..1b8da02 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "globby": "^8.0.2", "image-size": "^0.8.3", "inquirer": "^6.0.0", + "is-wsl": "^2.2.0", "lodash-id": "^0.14.0", "lowdb": "^1.0.0", "md5": "^2.2.1", diff --git a/src/utils/clipboard/wsl.sh b/src/utils/clipboard/wsl.sh new file mode 100644 index 0000000..332d820 --- /dev/null +++ b/src/utils/clipboard/wsl.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# grab the paths +scriptPath=$(echo $0 | awk '{ print substr( $0, 1, length($0)-6 ) }')"windows10.ps1" +imagePath=$(echo $1 | awk '{ print substr( $0, 1, length($0)-18 ) }') +imageName=$(echo $1 | awk '{ print substr( $0, length($0)-17, length($0) ) }') + +# run the powershell script +res=$(powershell.exe -noprofile -noninteractive -nologo -sta -executionpolicy unrestricted -file $(wslpath -w $scriptPath) $(wslpath -w $imagePath)"\\"$imageName) + +# note that there is a return symbol in powershell result +noImage=$(echo "no image\r") + +# check whether image exists +if [ "$res" = "$noImage" ] ;then + echo "no image" +else + echo $1 +fi diff --git a/src/utils/getClipboardImage.ts b/src/utils/getClipboardImage.ts index ac468e3..f16e9d5 100644 --- a/src/utils/getClipboardImage.ts +++ b/src/utils/getClipboardImage.ts @@ -3,11 +3,15 @@ import { spawn } from 'child_process' import dayjs from 'dayjs' import os from 'os' import fs from 'fs-extra' +import isWsl from 'is-wsl' import { IPicGo, IClipboardImage } from '../types' import { IBuildInEvent } from './enum' const getCurrentPlatform = (): string => { const platform = process.platform + if (isWsl) { + return 'wsl' + } if (platform !== 'win32') { return platform } else { @@ -34,7 +38,8 @@ const getClipboardImage = async (ctx: IPicGo): Promise => { darwin: env ? path.join(ctx.baseDir, 'mac.applescript') : './clipboard/mac.applescript', win32: env ? path.join(ctx.baseDir, 'windows.ps1') : './clipboard/windows.ps1', win10: env ? path.join(ctx.baseDir, 'windows10.ps1') : './clipboard/windows10.ps1', - linux: env ? path.join(ctx.baseDir, 'linux.sh') : './clipboard/linux.sh' + linux: env ? path.join(ctx.baseDir, 'linux.sh') : './clipboard/linux.sh', + wsl: env ? path.join(ctx.baseDir, 'wsl.sh') : './clipboard/wsl.sh' } const scriptPath = env ? platformPaths[platform] : path.join(__dirname, platformPaths[platform]) if (platform === 'darwin') { diff --git a/yarn.lock b/yarn.lock index 81d2a81..84894de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3234,6 +3234,11 @@ is-directory@^0.3.1: resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1" integrity sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE= +is-docker@^2.0.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa" + integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ== + is-extendable@^0.1.0, is-extendable@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" @@ -3380,6 +3385,13 @@ is-windows@^1.0.1, is-windows@^1.0.2: resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== +is-wsl@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" + integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== + dependencies: + is-docker "^2.0.0" + isarray@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"