- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
在使用 SSH 客户端 SSH 连接到远程 Ubuntu 终端后,我无法跨平台使用 Windows 10 和 Linux (Ubuntu) Putty .
在我的个人 GitHub 帐户中,我存储和编辑了一些代码文件(而不是在我的 PC 上存储和编辑它们)。其中一些文件是 Bourne shell 文件(.sh
文件)。
我想从我个人 GitHub 帐户中的文件中复制一些 Bash 代码,然后将其粘贴到 Bash 终端以直接执行:
Copy code from one of the files in GitHub (non-raw version).
Paste that code in terminal.
Execute that code by hitting Enter in terminal.
相关的 Bash 代码是以下代码(最初取自 here ),其中包含 Bash 脚本声明、2 个变量导出和带有 cat
here-document 的 Bash 函数, 缩进前导制表符缩进,以及函数的调用:
#!/bin/bash
export user="benqzq"
export repo="ulcwe"
preparations() {
cat <<-EOF >> "$HOME"/.bashrc
export s_a="/etc/nginx/sites-available"
export s_e="/etc/nginx/sites-enabled"
export drt="/var/www/html"
source "$HOME"/"$repo"/software_internal.sh
EOF
source "$HOME"/.bashrc 2>/dev/null
}
preparations
代码是用 Windows 字符复制的,例如 Windows 中常见的回车 (CR
) 行定界符,或可能会中断执行的前导空格(取决于我复制的特定代码,在这种情况下here-document 的意思是前导制表符缩进变成单个点或非制表符空格等,这在使用 here-documents 时是被禁止的)。
我希望我从 GitHub 复制到 Windows 10 剪贴板的代码被复制时没有前导空格和 CR。
我找不到 postprocessing solution in the Linux side (这基本上是将所有 Bash 代码输送到实用程序中,过滤掉 Windows 字符(如 dos2unix
或 sed "s/^[\t]//g"
)。
我确实找到了 AHk 的解决方案trimmed undesired characters in between copying and sending content to Windows clipboard 的 TrimClipboard() 函数.
鉴于我无法从 Linux (Bash) 端对代码进行后处理,并且鉴于我不想依赖于 AHk,我希望在免费时使用纯 JavaScript vanilla 方式将 GitHub 内容复制到 Windows 剪贴板中所有前导空格和 Windows 字符(尤其是 CR)。
有没有办法在 vanilla JavaScript 中进行这种“过滤复制”?我想到了一个 Greasemoneky 脚本,它将包含一个脚本来执行此操作,旨在仅在 github.com
中工作。
最佳答案
如果您能够运行 Greasemonkey 脚本,那么您可以尝试以下代码片段。这在 github 上的用户 benqzq
上执行,您可以更改它以扩展其工作域。事实上,我之前从未制作过 Greasemonkey 脚本,我不是 JS 专家,因此在正式运行之前可能需要进行一些测试。导入此脚本后,您必须选择所需的代码区域,然后修改后的版本将被复制到您的系统剪贴板:
// ==UserScript==
// @name CRLFRemover
// @version 1
// @match https://github.com/benqzq/*
// ==/UserScript==
// @https://stackoverflow.com/a/5379408/1020526
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
document.onmouseup = function() {
var text = getSelectionText();
// It should be of type `textarea` otherwise format will mess up
var input = document.createElement('textarea');
document.body.appendChild(input)
// Here we remove CRs
input.value = text.replace(/\r/g, '');
input.select();
document.execCommand('Copy', false);
input.remove();
}
关于JavaScript:从网络复制时, trim 所有前导空格以及所有 CR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48966685/
我正在使用 Ubuntu 15.04 和 vim-gnome 7.4。 当我运行时: vim --version | grep -i +ruby 它返回: +ruby 基于:Vim Ruby Supp
我正在编写一个测试脚本,它将简单地运行带有几个参数的 *.EXE 文件,然后将结果输出到一个文件。我有一个 *.sh 测试脚本可以正确运行测试(但需要手动更新更多测试)。此脚本中的行如下所示: bla
我想知道之间的区别(如果可能的话提供示例)CR LF (Windows)、LF (Unix) 和 CR (Macintosh) 换行符类型。 最佳答案 CR和LF是控制字符,分别编码为0x0D(十进制
我正在尝试使用 PHP 正则表达式来查找 CR 3492161 或 cr 3492161。我尝试使用以下正则表达式,但它不起作用。请求你的帮助。 :-) 'CR\s/^\d{7}$/' 'CR\h/^
交换换行符(例如通过某些文本编辑器)是否会破坏 javascript 代码? 最佳答案 两个控制字符都是valid line breaks .事实上你甚至不需要换行符。这只是为了更好的可读性。除了在字
这个问题已经有答案了: How to correct variable overwriting misbehavior when parsing output? (3 个回答) 已关闭 5 年前。 我
好的,我计划创建一个文件来存储我将导入到程序中的数据。该程序将为 Linux、Windows 和可能的 Mac 编译。 现在我真正想知道的是,由于这些文件中的换行符,我是否需要这些数据文件略有不同,或
建议以下计划: import java.io.StringReader; import javax.xml.transform.OutputKeys; import javax
我正在尝试将“,”和“\n”放入文件中。所有值都是 0 ,除了 4, 9, 14, 19, 23...我放置 ',' 和 '\n' 但是输出即将到来: 0000,0000,0000,0000,0000
我一直在尝试通过 Python 学习 Open ERP 模块开发。我想出了一个我认为我不理解的源代码。我在浏览时尝试了几个互联网链接,但找不到有用的链接。我非常需要理解这一点。 cr.execute(
我目前正在使用 JSP 生成一些 vCard。我发现一些平台无法识别这些生成的 vCard,除非它们的行由回车符 (CR) 分隔,而 JSP 似乎默认只使用换行符 (LF) 来分隔行。 你们知道有什么
验证用户时出现以下错误:purchase_user@purchase 失败。 MongoDB-CR 身份验证失败。当我通过浏览器访问网络服务时,用户文档中缺少凭据。 但我能够从 mongo 验证 pu
首先我想说我已经阅读了 this post但是我仍然对 CR line terminators 有问题. 有一个文件叫build_test.sh , 我编辑在 leafpad它可以直接显示在 Vim
我最近才开始使用 vim,并且在添加大量有用的插件时玩得很开心。问题是,在设置所有插件期间的某个时候,我没有注意到 enter 键的映射停止正常工作。在插入模式下,当我按下 Enter 键时,如果当前
我正在寻找一种在 vim 中突出显示 ^M(CR) 的方法。 最佳答案 确保文件格式设置为 unix 或 mac 我的是: set fileformats=unix,mac 如果是 DOS,您将看不到
假设我有一个程序(例如在Perl中),将这样的内容写入STDOUT: print "123\t- 456"; print "\r+\n"; 在我的屏幕上,我看到以下结果: 123 + 456
我正在编写一个在特定条件下自动插入一些文本的函数。当我尝试模拟 Enter press 时,我卡在了某个部分。我想出了这个(显而易见的)代码: execute "normal! a\" 问题是它破坏了
我有一个 HTML 页面中的元素。我正在用 JavaScript 向其中写入数据,并想稍后检查用户是否更改了文本。但是,如果数据包含任何回车符,它们似乎会被悄悄删除,因此将从文本区域读取的文本与应该存
各位正则表达式专家, 我有一个充满表达式的平面文件,例如: SELECT * FROM CONVENIENT_ONE_LINE_QUERY "SELECT * FROM THIS_QUERY WHER
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我是一名优秀的程序员,十分优秀!