2

For bash completion, I would like to replace youtube-dl with youtubedl.

I can make an alias for youtubedl, however, both youtube-dl with youtubedl will exist.

Primarily, I just want to remove youtube-dl from bash completion, and create a custom function for youtubedl.

TuxForLife
  • 2,909
  • depending on how much you're willing to type, you could append a personal bin directory to your $PATH that has an executable script named youtubedl which simply exec's youtube-dl; you would have to type "youtubedTAB" to get past the dash, though. – Jeff Schaller Apr 05 '16 at 19:19
  • 1
    as described here, if you are using at least Bash 4.4, EXECIGNORE=*/youtube-dl should do what you want. – Richard Waite Apr 08 '18 at 18:20

2 Answers2

1

Updated: Revised answer to clarify not for non-package installs

If you installed using the manual installation which was listed first on youtube-dl github page, then this method will allow you to use youtube-dl with your custom name youtubedl, without seeing youtube-dl in auto-completion. On your terminal:

$ cd /usr/local/bin/

$ sudo mv youtube-dl youtubedl

You may now use it using its new name youtubedl, try it with the test video:

$ youtubedl -F 'https://www.youtube.com/watch?v=BaW_jenozKc'

You may also upgrade in the future:

$ youtubedl -U

Warranty

  • Versions: 2016.01.15, renaming and then upgrading to 2016.04.05. See youtube-dl --version
  • Tested only with youtube-dl installed using the manual install instructions at the youtube-dl github page, not tested with package install methods. So this answer may not work if youtube-dl was installed with a package management system that might have the install location hard-coded

Explanation

The youtube-dl github page instructions followed were:

$ sudo curl https://yt-dl.org/latest/youtube-dl -o /usr/local/bin/youtube-dl
$ sudo chmod a+rx /usr/local/bin/youtube-dl
  • This downloads youtube-dl binary to /usr/local/bin.
  • Paths within $PATH appear on auto-completion.
  • /usr/local/bin is indeed one such path in $PATH, thus youtube-dl will appear in Bash auto-completion.

So to rename what appears in Bash auto-completion, one way is to rename the binary itself. We visit the binary's location:

$ cd /usr/local/bin/

Rename:

$ sudo mv youtube-dl youtubedl
  • /usr/local/bin is a restricted directory, so we use sudo

The old name will no longer be found:

$ which youtube-dl
youtube-dl not found

And we can now refer to it by the new name:

$ which youtubedl
/usr/local/bin/youtubedl

We can test it still works, for example upgrade with -U:

$ youtubedl -U
Updating to version 2016.04.05 ...
Updated youtube-dl. Restart youtube-dl to use the new version.

Test its video functionality such as retrieving formats:

$ youtubedl -F 'https://www.youtube.com/watch?v=BaW_jenozKc' | head
[youtube] BaW_jenozKc: Downloading webpage
[youtube] BaW_jenozKc: Downloading video info webpage
[youtube] BaW_jenozKc: Extracting video information
[youtube] BaW_jenozKc: Downloading MPD manifest
[info] Available formats for BaW_jenozKc:
format code  extension  resolution note
249          webm       audio only DASH audio   47k , opus @ 50k, 57.05KiB
250          webm       audio only DASH audio   66k , opus @ 70k, 79.56KiB
171          webm       audio only DASH audio   74k , vorbis@128k (44100Hz), 89.59K
iB
140          m4a        audio only DASH audio  127k , m4a_dash container, mp4a.40.2
@128k (44100Hz), 154.06KiB

From the source code update.py, line 86:

filename = sys.argv[0]
  • So this update code detects the current program's file name, thus allowing you to have yourcustomname -U and still successfully be able to update.
clarity123
  • 3,539
  • 1
    and if youtube-dl is part of a package that then gets upgraded? OP's alias will remain pointing at the previous version. – Jeff Schaller Apr 05 '16 at 18:39
  • I agree with Jeff, I would like to keep it there for package upgrades, I would totally prefer an alternative if there was a way around this. – TuxForLife Apr 05 '16 at 18:44
  • @JeffSchaller @user454038 Depending on the package manager, there might be a way to do this without it breaking on upgrade—e.g., with dpkg you can use dpkg-divert. (You should probably add this to your answer). – derobert Apr 05 '16 at 19:28
  • 1
    I probably should have clarified with OP how OP installed youtube-dl ... however I updated answer to clarify it is for manual installs, in case someone finds it helpful – clarity123 Apr 05 '16 at 20:00
  • Great answer, wish I could mark it as solved, but in this case, it has not solved my problem. It's a shame the command has a hyphen in it, it is giving me issues by loading my .bashrc file as a source file. – TuxForLife Apr 06 '16 at 00:12
0

What about ln -s /usr/bin/youtube-dl ~/bin/dlyoutube

techraf
  • 5,941
BaRud
  • 1,639
  • 2
  • 17
  • 26