Skip to content

Commit

Permalink
✨ Feature: add support for clipboard in wsl (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffersonQin committed Jul 27, 2021
1 parent 456b81c commit 3e230de
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions src/utils/clipboard/wsl.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion src/utils/getClipboardImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -34,7 +38,8 @@ const getClipboardImage = async (ctx: IPicGo): Promise<IClipboardImage> => {
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') {
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 3e230de

Please sign in to comment.