Skip to main content
added 64 characters in body
Source Link
ewen-goisot
  • 625
  • 5
  • 15

Step 3 : Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". This is the command you should put for your konsole shortcut. Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

Step 3 : Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

Step 3 : Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". This is the command you should put for your konsole shortcut. Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

Mod Moved Comments To Chat
added clipboard feature
Source Link
ewen-goisot
  • 625
  • 5
  • 15
  1. I assume the reader wants to do this with bash, konsole and a youtube-dl command, and the typed command should include clipboard content.

  2. Install tmux if you don't have it.

  3. Copy the 7 following lines and paste it to your ~/.bashrc file :

    bash_in_konsole(){ local IFS konsole -e bash --rcfile <(printf '. ~/.bashrc; set -m; %s\n' "$") } tmux_in_konsole(){ bash_in_konsole 'exec tmux new-session -A -t "temporary" ; run-shell "sleep .1" ; send-keys "C-u" "' "$" '" "C-l"' } (of course, the same can be done with some other terminals, like gnome-terminal).

  4. Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

    username@computer:~$ youtube-dl -f bestaudio[ext=m4a] http://youtube.com/watch?v=foobarlorem\&t=10s

Step 0 : I assume the reader wants to do this with bash, konsole and a youtube-dl command, and the typed command should include clipboard content. I also assume this is for a shortcut made in konsole (for other readers who will simply run it in terminal, make sure you reload your ~/.bashrc after editing it).

3bisStep 1 : Install tmux if you don't have it.

Step 2 : Copy the 7 following lines and paste it to your ~/.bashrc file (and save the file) :

bash_in_konsole(){
    local IFS
    konsole -e bash --rcfile <(printf '. ~/.bashrc; set -m; %s\n' "$*")
}

tmux_in_konsole(){
    bash_in_konsole 'exec tmux new-session -A -t "temporary" \; run-shell "sleep .1" \; send-keys "C-u" "' "$*" '" "C-l"'
}

Step 3 : Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

username@computer:~$ youtube-dl -f bestaudio[ext=m4a] http://youtube.com/watch?v=foobarlorem\&t=10s

Step 3 bis : (alternative to 3). If you don't want the clipboard content to be pasted, it's simpler. You can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] ". The expected result is:

Now, onceStep ω : (when you quit konsole) Once you have typed the URL of the video you want to download with youtube-dl, and you typed Enter, and you finished to download the video, you can quit this terminal.
To quit tmux, simply press Ctrl-bShift-d (you can also quit it the way you quit a shell, with Ctrl-d, but it means this tmux session will then be closed, and you will get huge numbers again).
If you accidentally closed konsole before the end of the download, tmux will allow it to run in the background. But don't do this purposely, because it may cause some problems (at least display-related) if you run a second instance of tmux_in_konsole while the first download didn't ended.

  1. I assume the reader wants to do this with bash, konsole and a youtube-dl command, and the typed command should include clipboard content.

  2. Install tmux if you don't have it.

  3. Copy the 7 following lines and paste it to your ~/.bashrc file :

    bash_in_konsole(){ local IFS konsole -e bash --rcfile <(printf '. ~/.bashrc; set -m; %s\n' "$") } tmux_in_konsole(){ bash_in_konsole 'exec tmux new-session -A -t "temporary" ; run-shell "sleep .1" ; send-keys "C-u" "' "$" '" "C-l"' } (of course, the same can be done with some other terminals, like gnome-terminal).

  4. Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

    username@computer:~$ youtube-dl -f bestaudio[ext=m4a] http://youtube.com/watch?v=foobarlorem\&t=10s

3bis. (alternative to 3). If you don't want the clipboard content to be pasted, it's simpler. You can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] ". The expected result is:

Now, once you have typed the URL of the video you want to download with youtube-dl, you can quit this terminal.
To quit tmux, simply press Ctrl-bShift-d (you can also quit it the way you quit a shell, with Ctrl-d, but it means this tmux session will then be closed, and you will get huge numbers again).

Step 0 : I assume the reader wants to do this with bash, konsole and a youtube-dl command, and the typed command should include clipboard content. I also assume this is for a shortcut made in konsole (for other readers who will simply run it in terminal, make sure you reload your ~/.bashrc after editing it).

Step 1 : Install tmux if you don't have it.

Step 2 : Copy the 7 following lines and paste it to your ~/.bashrc file (and save the file) :

bash_in_konsole(){
    local IFS
    konsole -e bash --rcfile <(printf '. ~/.bashrc; set -m; %s\n' "$*")
}

tmux_in_konsole(){
    bash_in_konsole 'exec tmux new-session -A -t "temporary" \; run-shell "sleep .1" \; send-keys "C-u" "' "$*" '" "C-l"'
}

Step 3 : Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

username@computer:~$ youtube-dl -f bestaudio[ext=m4a] http://youtube.com/watch?v=foobarlorem\&t=10s

Step 3 bis : (alternative to 3) If you don't want the clipboard content to be pasted, it's simpler. You can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] ". The expected result is:

Step ω : (when you quit konsole) Once you have typed the URL of the video you want to download with youtube-dl, and you typed Enter, and you finished to download the video, you can quit this terminal.
To quit tmux, simply press Ctrl-bShift-d (you can also quit it the way you quit a shell, with Ctrl-d, but it means this tmux session will then be closed, and you will get huge numbers again).
If you accidentally closed konsole before the end of the download, tmux will allow it to run in the background. But don't do this purposely, because it may cause some problems (at least display-related) if you run a second instance of tmux_in_konsole while the first download didn't ended.

added clipboard feature
Source Link
ewen-goisot
  • 625
  • 5
  • 15

I was first thinking about xdotool to type text, but it will be some issues if the konsole window isn't focused. Usually, tmux isn't pre-installed. On a Debian-based distro, the command to install it is sudo apt-get install tmux. Actually, tmux has a send-keys feature. Of course, if it's with tmux, you should run a tmux session. Maybe you will need to install tmux first. Try this if you want to understand how this works :

Official solution,Clipboard without the "Enter" (merge of the 2 previous partsnewline) at the end:

WhatIf you couldcopied the URL http://youtube.com/foobar, the output of xsel -ob contains a trailing newline \n (the same char you usually get when you press Enter). Depending on the context, there are several things you can do is this :

bash_in_konsole(){
    local IFS
    konsole -e bash --rcfile <(printf '. ~/.bashrc; set -m; %s\n' "$*")
}
tmux_in_konsole(){
    bash_in_konsole 'exec tmux new-session -A -t "temporary" \; run-shell "sleep .1" \; send-keys "C-u" "' "$*" '" "C-l"'
}
  • To get only the first line without a trailing space : xsel -ob | head -1 | tr -d "\n"
  • To put spaces instead of newlines : xsel -ob | tr "\n" " ".
    why a space and not "nothing"? Because you may have copied several URL (several lines) and youtube-dl can download a space-separated set of videos.

(of coursewarning: : in your case, you are using youtube-dl, and YouTube's URL may include timestamp like http://youtube.com/foobar&t=21m17s meaning the same canvideo will automatically start at 21:17 when you launch it in web browser. Also, for some reason, timestamps may appear automatically. And the ampersand & is the bash command to do a fork. It means it will be donedifficult to calcel it with some other terminalsCtrl-c if you accidently pressed Enter. You may also want to escape the characters that are both usually escaped and presents in YouTube's URL, like gnome-terminal? and =, but for zsh (and maybe some other shells) users only : using zsh, the ? causes a no matches found error message.

  • bash, To escape the ampersand only : xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g".
  • zsh , To escape the 3 problematic symbols : xsel -ob | tr "\n" " " | sed "s/\(?\|=\|&\)/\\\\\1/g".
    note: most of time, I assume the reader is a bash user, but I personally use zsh, so most commands are supposed to work with zsh too. If you face an issue with another shell, please, let me know.

Official solution, (merge of the 3 previous parts) :

  1. I assume the reader wants to do this with bash, konsole and a youtube-dl command, and the typed command should include clipboard content.

  2. Install tmux if you don't have it.

  3. Copy the 7 following lines and paste it to your ~/.bashrc file :

    bash_in_konsole(){ local IFS konsole -e bash --rcfile <(printf '. ~/.bashrc; set -m; %s\n' "$") } tmux_in_konsole(){ bash_in_konsole 'exec tmux new-session -A -t "temporary" ; run-shell "sleep .1" ; send-keys "C-u" "' "$" '" "C-l"' } (of course, the same can be done with some other terminals, like gnome-terminal).

  4. Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

    username@computer:~$ youtube-dl -f bestaudio[ext=m4a] http://youtube.com/watch?v=foobarlorem\&t=10s

Now,3bis. (alternative to 3). If you don't want the clipboard content to be pasted, it's simpler. You can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] ", the. The expected result is:

Note: I revomedremoved every other part of my comment because it is messy and I first misunderstood a part of your question.
  I think there is still a way to see it by seeing the revisions history. I also keep a copy of it on my computer if needed.
Note: personal zsh shortcut is Ctrl-Alt-l instead of Ctrl-l, if you still see the first one, it's a pasting mistake from me. If you see this note, it could also be a pasting mistake from me ! (but this time, it wasn't)


Step by step:

  1. Install tmux
  2. open your bash config file, usually, it's ~/.bashrc
  3. copy and paste the "functions" (the 7 lines just after "what you could do is this" at the end of the ~/.bashrc file,
  4. open a new terminal to make sure the ~/.bashrc changes are active
  5. run tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a]"
  6. Expected result : it opens a new terminal with a typed command inside.

I was first thinking about xdotool to type text, but it will be some issues if the konsole window isn't focused. Actually, tmux has a send-keys feature. Of course, if it's with tmux, you should run a tmux session. Maybe you will need to install tmux first. Try this if you want to understand how this works :

Official solution, (merge of the 2 previous parts) :

What you could do is this :

bash_in_konsole(){
    local IFS
    konsole -e bash --rcfile <(printf '. ~/.bashrc; set -m; %s\n' "$*")
}
tmux_in_konsole(){
    bash_in_konsole 'exec tmux new-session -A -t "temporary" \; run-shell "sleep .1" \; send-keys "C-u" "' "$*" '" "C-l"'
}

(of course, the same can be done with some other terminals, like gnome-terminal).

Now, you can test tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] ", the expected result is:

Note: I revomed every other part of my comment because it is messy and I first misunderstood a part of your question.
  I think there is still a way to see it by seeing the revisions history. I also keep a copy of it on my computer if needed.


Step by step:

  1. Install tmux
  2. open your bash config file, usually, it's ~/.bashrc
  3. copy and paste the "functions" (the 7 lines just after "what you could do is this" at the end of the ~/.bashrc file,
  4. open a new terminal to make sure the ~/.bashrc changes are active
  5. run tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a]"
  6. Expected result : it opens a new terminal with a typed command inside.

I was first thinking about xdotool to type text, but it will be some issues if the konsole window isn't focused. Usually, tmux isn't pre-installed. On a Debian-based distro, the command to install it is sudo apt-get install tmux. Actually, tmux has a send-keys feature. Of course, if it's with tmux, you should run a tmux session. Maybe you will need to install tmux first. Try this if you want to understand how this works :

Clipboard without the "Enter" (newline) at the end:

If you copied the URL http://youtube.com/foobar, the output of xsel -ob contains a trailing newline \n (the same char you usually get when you press Enter). Depending on the context, there are several things you can do :

  • To get only the first line without a trailing space : xsel -ob | head -1 | tr -d "\n"
  • To put spaces instead of newlines : xsel -ob | tr "\n" " ".
    why a space and not "nothing"? Because you may have copied several URL (several lines) and youtube-dl can download a space-separated set of videos.

warning: : in your case, you are using youtube-dl, and YouTube's URL may include timestamp like http://youtube.com/foobar&t=21m17s meaning the video will automatically start at 21:17 when you launch it in web browser. Also, for some reason, timestamps may appear automatically. And the ampersand & is the bash command to do a fork. It means it will be difficult to calcel it with Ctrl-c if you accidently pressed Enter. You may also want to escape the characters that are both usually escaped and presents in YouTube's URL, like ? and =, but for zsh (and maybe some other shells) users only : using zsh, the ? causes a no matches found error message.

  • bash, To escape the ampersand only : xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g".
  • zsh , To escape the 3 problematic symbols : xsel -ob | tr "\n" " " | sed "s/\(?\|=\|&\)/\\\\\1/g".
    note: most of time, I assume the reader is a bash user, but I personally use zsh, so most commands are supposed to work with zsh too. If you face an issue with another shell, please, let me know.

Official solution, (merge of the 3 previous parts) :

  1. I assume the reader wants to do this with bash, konsole and a youtube-dl command, and the typed command should include clipboard content.

  2. Install tmux if you don't have it.

  3. Copy the 7 following lines and paste it to your ~/.bashrc file :

    bash_in_konsole(){ local IFS konsole -e bash --rcfile <(printf '. ~/.bashrc; set -m; %s\n' "$") } tmux_in_konsole(){ bash_in_konsole 'exec tmux new-session -A -t "temporary" ; run-shell "sleep .1" ; send-keys "C-u" "' "$" '" "C-l"' } (of course, the same can be done with some other terminals, like gnome-terminal).

  4. Now, you can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] $(xsel -ob | tr "\n" " " | sed "s/&/\\\\&/g")". Let's say you copied the URL http://youtube.com/watch?v=foobarlorem&t=10s. The expected result is:

    username@computer:~$ youtube-dl -f bestaudio[ext=m4a] http://youtube.com/watch?v=foobarlorem\&t=10s

3bis. (alternative to 3). If you don't want the clipboard content to be pasted, it's simpler. You can test with tmux_in_konsole "youtube-dl -f bestaudio[ext=m4a] ". The expected result is:

Note: I removed every other part of my comment because it is messy and I first misunderstood a part of your question. I think there is still a way to see it by seeing the revisions history. I also keep a copy of it on my computer if needed.
Note: personal zsh shortcut is Ctrl-Alt-l instead of Ctrl-l, if you still see the first one, it's a pasting mistake from me. If you see this note, it could also be a pasting mistake from me ! (but this time, it wasn't)

Made it Bash-compatible, removed the c-M-l
Source Link
ewen-goisot
  • 625
  • 5
  • 15
Loading
changed everything. Trying to give a more relevant answer.
Source Link
ewen-goisot
  • 625
  • 5
  • 15
Loading
added 1005 characters in body
Source Link
ewen-goisot
  • 625
  • 5
  • 15
Loading
Post Undeleted by ewen-goisot
added 333 characters in body
Source Link
ewen-goisot
  • 625
  • 5
  • 15
Loading
Post Deleted by ewen-goisot
multi-user -> vim's clipboard past doesn't work
Source Link
ewen-goisot
  • 625
  • 5
  • 15
Loading
Source Link
ewen-goisot
  • 625
  • 5
  • 15
Loading