{"id":16902231,"url":"https://github.com/keystroke3/snippets","last_synced_at":"2026-04-10T07:48:52.416Z","repository":{"id":102465911,"uuid":"237204192","full_name":"keystroke3/snippets","owner":"keystroke3","description":"A collection of small bits of code that make my life easier on linux","archived":false,"fork":false,"pushed_at":"2020-02-05T19:20:08.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-25T14:13:23.646Z","etag":null,"topics":["bash","linux","python","shell","snippets","zsh"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keystroke3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-30T12:02:18.000Z","updated_at":"2021-05-29T03:25:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"ecb697e4-1e69-4101-8588-01f4a90db919","html_url":"https://github.com/keystroke3/snippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keystroke3%2Fsnippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keystroke3%2Fsnippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keystroke3%2Fsnippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keystroke3%2Fsnippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keystroke3","download_url":"https://codeload.github.com/keystroke3/snippets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244637103,"owners_count":20485446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","linux","python","shell","snippets","zsh"],"created_at":"2024-10-13T18:04:18.789Z","updated_at":"2026-04-10T07:48:47.369Z","avatar_url":"https://github.com/keystroke3.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# snippets\nA collection of small bits of code that make my life easier on linux\n## Navigation\nsnippets that help you move around terminal quickly. Just add the snippet you want to `.bashrc` or `.zshrc`. For all the snippets here, it is best to have [FZF](https://github.com/junegunn/fzf) installed on your system. If you want to change the start location, simply change `$HOME` to whatever you want. Note that if you choose to start from root (/), it might take some time to work, since it looks through the entire system.\n### Jump to any directory from any directory.\n\n```shell\n#!/bin/sh\n\nj(){\n    fuzz=`fd -Ht d . $HOME | fzf --reverse --height 40%`\n    if [ -z $fuzz ]\n    then \n        return 0\n    elif [ -d $fuzz ]\n    then\n        cd $fuzz\n    fi\n}\n\n```\nNow type `j` and press enter. \n\n### Open any file from anywhere.\n```shell\n#!/bin/sh\n\no(){\n    fuzz=`fzf --reverse --height 40%`\n    if [ -z $fuzz ]\n    then \n        return 0\n    elif [ -f $fuzz ]\n    then\n        filetype=`xdg-mime query filetype $fuzz | awk -F/ '{print $1}'`\n        case $filetype in\n            text )\n                vim $fuzz ;;\n            audio )\n               nohup mpv $fuzz ;;\n            application )\n                vim $fuzz ;;\n            * )\n                nohup xdg-open $fuzz \u003e /dev/null 2\u003e\u00261\n        esac\n    fi\n}\n\n```\ntyp `o` then enter. Vim is my text editor of choice and this is what I use here. If you wish to change or use a different one, just change `vim` to whatever text editor you want. If your text editor is a graphical one like Gvim or Gedit, you can should add `nohup` before like so:\n```\ntext )\n    nohup gedit $fuzz ;;\n```\nNohup is there only to allow you to keep using you terminal after the program has lauched.\n\n## File Manipulaton\n### How to separate a list of files and directories stored in a text file\n\nIf you have a list of files and directories all in one text file and wan to seperate them to different files Here is what you can do \nin python:\n\n```python\n#!/bin/python3\n\nworking_dir = \"Documents/teams/\"\nwith open(working_dir+\"original.txt\", \"r\") as full_list:\n    with open(working_dir+\"only_dirs.txt\", \"a\") as dirs, \\\n            open(working_dir+\"only_files.txt\", \"a\") as files:\n        lines = full_list.readlines()\n        for line in lines:\n            if \".\" not in line[-6:] or line[-1:] == \"/\":\n                dirs.write(line)\n                print(f\"... {line[-50:]} is a directory\")\n            else:\n                files.write(line)\n                print(f\"... {line[-50:]} is a file\")\n```\nLooking at the code above, we first start by specifiying the directory where our files are and where they will be stored. This can be ignored if you are using this python file in the same directory as the files in question. We the the `open` to open file with the list of paths and new files in append mode. We then read the paths file and store the contents in a `lines` variable. We then iterate through the the lines and check if the lines end with a file extension. The line `if \".\" not in line[-6:]:` just checks if the last few characters have a \".\" (dot) in them. This is because all file extensions are of the form `.*` where * can be any character or set of characters. Incase the line ends with `/` then it is treated as a directory.  \nif a line has no file extension or ends with \"/\" then it is assumed to be a directory and is adde to the `only_dirs.txt` file. otherwise, it is placed in the `only_files.txt` file. The print statements are just for feedback and can be ignored.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeystroke3%2Fsnippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeystroke3%2Fsnippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeystroke3%2Fsnippets/lists"}