mirror of
https://github.com/chubin/cheat.sh.git
synced 2026-06-20 13:16:44 +02:00
Merge pull request #264 from chubin/fixes
Show multiple cheat sheets when found (#147)
This commit is contained in:
@@ -11,7 +11,7 @@ Exports:
|
||||
import re
|
||||
import json
|
||||
|
||||
from routing import get_answer_dict, get_topics_list
|
||||
from routing import get_answers, get_topics_list
|
||||
from search import find_answers_by_keyword
|
||||
from languages_data import LANGUAGE_ALIAS, rewrite_editor_section_name
|
||||
import postprocessing
|
||||
@@ -98,7 +98,7 @@ def cheat_wrapper(query, request_options=None, output_format='ansi'):
|
||||
answers = find_answers_by_keyword(
|
||||
topic, keyword, options=search_options, request_options=request_options)
|
||||
else:
|
||||
answers = [get_answer_dict(topic, request_options=request_options)]
|
||||
answers = get_answers(topic, request_options=request_options)
|
||||
|
||||
answers = [
|
||||
postprocessing.postprocess(
|
||||
|
||||
+12
-6
@@ -101,6 +101,10 @@ def _visualize(answers, request_options, search_mode=False):
|
||||
if color_style not in CONFIG['frontend.styles']:
|
||||
color_style = ''
|
||||
|
||||
# if there is more than one answer,
|
||||
# show the source of the answer
|
||||
multiple_answers = len(answers) > 1
|
||||
|
||||
found = True
|
||||
result = ""
|
||||
for answer_dict in answers:
|
||||
@@ -109,14 +113,16 @@ def _visualize(answers, request_options, search_mode=False):
|
||||
answer = answer_dict['answer']
|
||||
found = found and not topic_type == 'unknown'
|
||||
|
||||
if search_mode and topic != 'LIMITED':
|
||||
if multiple_answers and topic != 'LIMITED':
|
||||
section_name = f"{topic_type}:{topic}"
|
||||
|
||||
if not highlight:
|
||||
result += "\n[%s]\n" % topic
|
||||
result += f"#[{section_name}]\n"
|
||||
else:
|
||||
result += "\n%s%s %s %s%s\n" % (
|
||||
colored.bg('dark_gray'), colored.attr("res_underlined"),
|
||||
topic,
|
||||
colored.attr("res_underlined"), colored.attr('reset'))
|
||||
result += "".join([
|
||||
"\n", colored.bg('dark_gray'), colored.attr("res_underlined"),
|
||||
f" {section_name} ",
|
||||
colored.attr("res_underlined"), colored.attr('reset'), "\n"])
|
||||
|
||||
if answer_dict['format'] in ['ansi', 'text']:
|
||||
result += answer
|
||||
|
||||
+66
-35
@@ -4,12 +4,13 @@ Queries routing and caching.
|
||||
Exports:
|
||||
|
||||
get_topics_list()
|
||||
get_answer_dict()
|
||||
get_answers()
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
import random
|
||||
import re
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import cache
|
||||
import adapter.cheat_sheets
|
||||
import adapter.cmd
|
||||
@@ -83,20 +84,28 @@ class Router(object):
|
||||
self._cached_topics_list = answer
|
||||
return answer
|
||||
|
||||
def get_topic_type(self, topic):
|
||||
def get_topic_type(self, topic: str) -> List[str]:
|
||||
"""
|
||||
Return topic type for `topic` or "unknown" if topic can't be determined.
|
||||
Return list of topic types for `topic`
|
||||
or ["unknown"] if topic can't be determined.
|
||||
"""
|
||||
|
||||
def __get_topic_type(topic):
|
||||
def __get_topic_type(topic: str) -> List[str]:
|
||||
result = []
|
||||
for regexp, route in self.routing_table:
|
||||
if re.search(regexp, topic):
|
||||
if route in self._adapter:
|
||||
if self._adapter[route].is_found(topic):
|
||||
return route
|
||||
result.append(route)
|
||||
else:
|
||||
return route
|
||||
return CONFIG["routing.default"]
|
||||
result.append(route)
|
||||
if not result:
|
||||
return [CONFIG["routing.default"]]
|
||||
|
||||
# cut the default route off, if there are more than one route found
|
||||
if len(result) > 1:
|
||||
return result[:-1]
|
||||
return result
|
||||
|
||||
if topic not in self._cached_topic_type:
|
||||
self._cached_topic_type[topic] = __get_topic_type(topic)
|
||||
@@ -111,7 +120,9 @@ class Router(object):
|
||||
|
||||
def handle_if_random_request(self, topic):
|
||||
"""
|
||||
Check if the `query` if a :random one, if yes we check its correctness and then randomly select a topic, based on the provided prefix.
|
||||
Check if the `query` is a :random one,
|
||||
if yes we check its correctness and then randomly select a topic,
|
||||
based on the provided prefix.
|
||||
|
||||
"""
|
||||
|
||||
@@ -152,60 +163,80 @@ class Router(object):
|
||||
#Here if not a random requst, we just forward the topic
|
||||
return topic
|
||||
|
||||
def get_answer_dict(self, topic, request_options=None):
|
||||
def get_answers(self, topic: str, request_options:Dict[str, str] = None) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Find cheat sheet for the topic.
|
||||
Find cheat sheets for the topic.
|
||||
|
||||
Args:
|
||||
`topic` (str): the name of the topic of the cheat sheet
|
||||
|
||||
Returns:
|
||||
answer_dict: the answer dictionary
|
||||
[answer_dict]: list of answers (dictionaries)
|
||||
"""
|
||||
|
||||
# if topic specified as <topic_type>:<topic>,
|
||||
# cut <topic_type> off
|
||||
topic_type = ""
|
||||
if re.match("[^/]+:", topic):
|
||||
topic_type, topic = topic.split(":", 1)
|
||||
|
||||
topic = self.handle_if_random_request(topic)
|
||||
topic_type = self.get_topic_type(topic)
|
||||
topic_types = self.get_topic_type(topic)
|
||||
|
||||
# if topic_type is specified explicitly,
|
||||
# show pages only of that type
|
||||
if topic_type and topic_type in topic_types:
|
||||
topic_types = [topic_type]
|
||||
|
||||
# 'question' queries are pretty expensive, that's why they should be handled
|
||||
# in a special way:
|
||||
# we do not drop the old style cache entries and try to reuse them if possible
|
||||
if topic_type == 'question':
|
||||
if topic_types == ['question']:
|
||||
answer = cache.get('q:' + topic)
|
||||
if answer:
|
||||
if isinstance(answer, dict):
|
||||
return answer
|
||||
return {
|
||||
return [answer]
|
||||
return [{
|
||||
'topic': topic,
|
||||
'topic_type': 'question',
|
||||
'answer': answer,
|
||||
'format': 'text+code',
|
||||
}
|
||||
}]
|
||||
|
||||
answer = self._get_page_dict(topic, topic_type, request_options=request_options)
|
||||
answer = self._get_page_dict(topic, topic_types[0], request_options=request_options)
|
||||
if answer.get("cache", True):
|
||||
cache.put('q:' + topic, answer)
|
||||
return answer
|
||||
return [answer]
|
||||
|
||||
# Try to find cacheable queries in the cache.
|
||||
# If answer was not found in the cache, resolve it in a normal way and save in the cache
|
||||
cache_needed = self._adapter[topic_type].is_cache_needed()
|
||||
if cache_needed:
|
||||
answer = cache.get(topic)
|
||||
if not isinstance(answer, dict):
|
||||
answer = None
|
||||
if answer:
|
||||
return answer
|
||||
answers = []
|
||||
for topic_type in topic_types:
|
||||
|
||||
answer = self._get_page_dict(topic, topic_type, request_options=request_options)
|
||||
if isinstance(answer, dict):
|
||||
if "cache" in answer:
|
||||
cache_needed = answer["cache"]
|
||||
cache_entry_name = f"{topic_type}:{topic}"
|
||||
cache_needed = self._adapter[topic_type].is_cache_needed()
|
||||
|
||||
if cache_needed and answer:
|
||||
cache.put(topic, answer)
|
||||
return answer
|
||||
if cache_needed:
|
||||
answer = cache.get(cache_entry_name)
|
||||
if not isinstance(answer, dict):
|
||||
answer = None
|
||||
if answer:
|
||||
answers.append(answer)
|
||||
continue
|
||||
|
||||
answer = self._get_page_dict(topic, topic_type, request_options=request_options)
|
||||
if isinstance(answer, dict):
|
||||
if "cache" in answer:
|
||||
cache_needed = answer["cache"]
|
||||
|
||||
if cache_needed and answer:
|
||||
cache.put(cache_entry_name, answer)
|
||||
|
||||
answers.append(answer)
|
||||
|
||||
return answers
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
_ROUTER = Router()
|
||||
get_topics_list = _ROUTER.get_topics_list
|
||||
get_answer_dict = _ROUTER.get_answer_dict
|
||||
get_answers = _ROUTER.get_answers
|
||||
|
||||
+6
-5
@@ -22,7 +22,7 @@ Configuration parameters:
|
||||
import re
|
||||
|
||||
from config import CONFIG
|
||||
from routing import get_answer_dict, get_topics_list
|
||||
from routing import get_answers, get_topics_list
|
||||
|
||||
def _limited_entry():
|
||||
return {
|
||||
@@ -100,10 +100,11 @@ def find_answers_by_keyword(directory, keyword, options="", request_options=None
|
||||
if not options_dict["recursive"] and '/' in subtopic:
|
||||
continue
|
||||
|
||||
answer_dict = get_answer_dict(topic, request_options=request_options)
|
||||
answer_text = answer_dict.get('answer', '')
|
||||
if match(answer_text, keyword, options_dict=options_dict):
|
||||
answers_found.append(answer_dict)
|
||||
answer_dicts = get_answers(topic, request_options=request_options)
|
||||
for answer_dict in answer_dicts:
|
||||
answer_text = answer_dict.get('answer', '')
|
||||
if match(answer_text, keyword, options_dict=options_dict):
|
||||
answers_found.append(answer_dict)
|
||||
|
||||
if len(answers_found) > CONFIG['search.limit']:
|
||||
answers_found.append(
|
||||
|
||||
+48
-19
@@ -1,14 +1,18 @@
|
||||
[48;5;8m[24m cheat.sheets:az [24m[0m
|
||||
[38;5;246;03m# Microsoft Azure CLI 2.0[39;00m
|
||||
[38;5;246;03m# Command-line tools for Azure[39;00m
|
||||
|
||||
[38;5;246;03m# Install Azure CLI 2.0 with one curl command.[39;00m
|
||||
[38;5;252mcurl[39m[38;5;252m [39m[38;5;252m-L[39m[38;5;252m [39m[38;5;252mhttps://aka.ms/InstallAzureCli[39m[38;5;252m [39m[38;5;252m|[39m[38;5;252m [39m[38;5;252mbash[39m
|
||||
|
||||
[38;5;246;03m# create a resource group named "MyResourceGroup" in the westus2 region of Azure[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mgroup[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyResourceGroup[39m[38;5;252m [39m[38;5;252m-l[39m[38;5;252m [39m[38;5;252mwestus2[39m
|
||||
[38;5;246;03m# create a resource group named "MyRG" in the 'westus2' region[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mgroup[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyRG[39m[38;5;252m [39m[38;5;252m-l[39m[38;5;252m [39m[38;5;252mwestus2[39m
|
||||
|
||||
[38;5;246;03m# create a Linux VM using the UbuntuTLS image, with two attached storage disks of 10 GB and 20 GB[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyResourceGroup[39m[38;5;252m [39m[38;5;252m--ssh-key-value[39m[38;5;252m [39m[38;5;87m$HOME[39m[38;5;252m/.ssh/id_rsa.pub[39m[38;5;252m [39m[38;5;252m--image[39m[38;5;252m [39m[38;5;252mUbuntuLTS[39m[38;5;252m [39m[38;5;252m--data-disk-sizes-gb[39m[38;5;252m [39m[38;5;67m10[39m[38;5;252m [39m[38;5;67m20[39m
|
||||
[38;5;246;03m# create a Linux VM using the UbuntuTLS image,[39;00m
|
||||
[38;5;246;03m# with two attached storage disks of 10 GB and 20 GB[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyRG[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--ssh-key-value[39m[38;5;252m [39m[38;5;87m$HOME[39m[38;5;252m/.ssh/id_rsa.pub[39m[38;5;252m [39m[38;5;252m--image[39m[38;5;252m [39m[38;5;252mUbuntuLTS[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--data-disk-sizes-gb[39m[38;5;252m [39m[38;5;67m10[39m[38;5;252m [39m[38;5;67m20[39m
|
||||
|
||||
[38;5;246;03m# list VMs[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m--output[39m[38;5;252m [39m[38;5;252mtable[39m
|
||||
@@ -16,28 +20,28 @@
|
||||
[38;5;246;03m# list only VMs having distinct state[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m-d[39m[38;5;252m [39m[38;5;252m--query[39m[38;5;252m [39m[38;5;214m"[?powerState=='VM running']"[39m[38;5;252m [39m[38;5;252m--output[39m[38;5;252m [39m[38;5;252mtable[39m
|
||||
|
||||
[38;5;246;03m# delete VM (with the name MyLinuxVM in the group MyResourceGroup)[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mdelete[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyResourceGroup[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m[38;5;252m [39m[38;5;252m--yes[39m
|
||||
[38;5;246;03m# delete VM (with the name MyLinuxVM in the group MyRG)[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mdelete[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyRG[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m[38;5;252m [39m[38;5;252m--yes[39m
|
||||
|
||||
[38;5;246;03m# Delete all VMs in a resource group[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mdelete[39m[38;5;252m [39m[38;5;252m--ids[39m[38;5;252m [39m[38;5;70;01m$([39;00m[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyResourceGroup[39m[38;5;252m [39m[38;5;252m--query[39m[38;5;252m [39m[38;5;214m"[].id"[39m[38;5;252m [39m[38;5;252m-o[39m[38;5;252m [39m[38;5;252mtsv[39m[38;5;70;01m)[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mdelete[39m[38;5;252m [39m[38;5;252m--ids[39m[38;5;252m [39m[38;5;70;01m$([39;00m[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyRG[39m[38;5;252m [39m[38;5;252m--query[39m[38;5;252m [39m[38;5;214m"[].id"[39m[38;5;252m [39m[38;5;252m-o[39m[38;5;252m [39m[38;5;252mtsv[39m[38;5;70;01m)[39;00m
|
||||
|
||||
[38;5;246;03m# Create an Image based on a running VM[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mdeallocate[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyResourceGroup[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mgeneralize[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyResourceGroup[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mimage[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;252mMyResourceGroup[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;252mMyTestImage[39m[38;5;252m [39m[38;5;252m--source[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mdeallocate[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyRG[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mgeneralize[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mMyRG[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mimage[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;252mMyRG[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;252mMyTestImage[39m[38;5;252m [39m[38;5;252m--source[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m
|
||||
|
||||
[38;5;246;03m# Running VM based on a VHD[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mstorage[39m[38;5;252m [39m[38;5;252mblob[39m[38;5;252m [39m[38;5;252mupload[39m[38;5;252m [39m[38;5;252m--account-name[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87maccount_name[39m[38;5;214m}[39m[38;5;214m"[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--account-key[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87maccount_key[39m[38;5;214m}[39m[38;5;214m"[39m[38;5;252m [39m[38;5;252m--container-name[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87mcontainer_name[39m[38;5;214m}[39m[38;5;214m"[39m[38;5;252m [39m[38;5;252m--type[39m[38;5;252m [39m[38;5;252mpage[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--file[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87mfile[39m[38;5;214m}[39m[38;5;214m"[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87mvhd_name[39m[38;5;214m}[39m[38;5;214m"[39m
|
||||
[38;5;252m [39m[38;5;252m--account-key[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87maccount_key[39m[38;5;214m}[39m[38;5;214m"[39m[38;5;252m [39m[38;5;252m--container-name[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87mcontainer[39m[38;5;214m}[39m[38;5;214m"[39m[38;5;252m [39m[38;5;252m--type[39m[38;5;252m [39m[38;5;252mpage[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--file[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87mfile[39m[38;5;214m}[39m[38;5;214m"[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87mvhd[39m[38;5;214m}[39m[38;5;214m"[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mdisk[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;214m${[39m[38;5;87mresource_group[39m[38;5;214m}[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214m${[39m[38;5;87mresource_group[39m[38;5;214m}[39m[38;5;214m"[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;252mmyManagedDisk[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--source[39m[38;5;252m [39m[38;5;252mhttps://[39m[38;5;214m${[39m[38;5;87maccount_name[39m[38;5;214m}[39m[38;5;252m.blob.core.windows.net/[39m[38;5;214m${[39m[38;5;87mcontainer_name[39m[38;5;214m}[39m[38;5;252m/[39m[38;5;214m${[39m[38;5;87mvhd_name[39m[38;5;214m}[39m
|
||||
[38;5;252m [39m[38;5;252m--source[39m[38;5;252m [39m[38;5;214m"[39m[38;5;214mhttps://[39m[38;5;214m${[39m[38;5;87maccount_name[39m[38;5;214m}[39m[38;5;214m.blob.core.windows.net/[39m[38;5;214m${[39m[38;5;87mcontainer[39m[38;5;214m}[39m[38;5;214m/[39m[38;5;214m${[39m[38;5;87mvhd[39m[38;5;214m}[39m[38;5;214m"[39m
|
||||
|
||||
[38;5;246;03m# open port[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mopen-port[39m[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;252mMyResourceGroup[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m[38;5;252m [39m[38;5;252m--port[39m[38;5;252m [39m[38;5;67m443[39m[38;5;252m [39m[38;5;252m--priority[39m[38;5;252m [39m[38;5;67m899[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mopen-port[39m[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;252mMyRG[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;252mMyLinuxVM[39m[38;5;252m [39m[38;5;252m--port[39m[38;5;252m [39m[38;5;67m443[39m[38;5;252m [39m[38;5;252m--priority[39m[38;5;252m [39m[38;5;67m899[39m
|
||||
|
||||
[38;5;246;03m# Show storage accounts[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mstorage[39m[38;5;252m [39m[38;5;252maccount[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m--output[39m[38;5;252m [39m[38;5;252mtable[39m
|
||||
@@ -46,7 +50,8 @@
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mstorage[39m[38;5;252m [39m[38;5;252mcontainer[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m--account-name[39m[38;5;252m [39m[38;5;252mmystorageaccount[39m[38;5;252m [39m[38;5;252m--output[39m[38;5;252m [39m[38;5;252mtable[39m
|
||||
|
||||
[38;5;246;03m# Show blobs in a container[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mstorage[39m[38;5;252m [39m[38;5;252mblob[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m--account-name[39m[38;5;252m [39m[38;5;252mmystorageaccount[39m[38;5;252m [39m[38;5;252m--container-name[39m[38;5;252m [39m[38;5;252mmycontainer[39m[38;5;252m [39m[38;5;252m--output[39m[38;5;252m [39m[38;5;252mtable[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mstorage[39m[38;5;252m [39m[38;5;252mblob[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m--account-name[39m[38;5;252m [39m[38;5;252mmystorageaccount[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--container-name[39m[38;5;252m [39m[38;5;252mmycontainer[39m[38;5;252m [39m[38;5;252m--output[39m[38;5;252m [39m[38;5;252mtable[39m
|
||||
|
||||
[38;5;246;03m# list account keys[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mstorage[39m[38;5;252m [39m[38;5;252maccount[39m[38;5;252m [39m[38;5;252mkeys[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252m--account-name[39m[38;5;252m [39m[38;5;252mSTORAGE_NAME[39m[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;252mRESOURCE_GROUP[39m
|
||||
@@ -62,8 +67,8 @@
|
||||
|
||||
[38;5;246;03m# Copy blob[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mstorage[39m[38;5;252m [39m[38;5;252mblob[39m[38;5;252m [39m[38;5;252mcopy[39m[38;5;252m [39m[38;5;252mstart[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--source-uri[39m[38;5;252m [39m[38;5;214m'https://md-ldh5nknx2rkz.blob.core.windows.net/jzwuuuzzapn0/abcd?sv=2017-04-17&sr=b&si=68041718-6828-4f5e-9e6e-a1b719975062&sig=XXX'[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--account-key[39m[38;5;252m [39m[38;5;87mXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX[39m[38;5;252m=[39m[38;5;252m=[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--source-uri[39m[38;5;252m [39m[38;5;214m'https://xxx.blob.core.windows.net/jzwuuuzzapn0/abcd?...'[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--account-key[39m[38;5;252m [39m[38;5;87mXXXXXXXXXX[39m[38;5;252m=[39m[38;5;252m=[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--account-name[39m[38;5;252m [39m[38;5;252mdestaccount[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--destination-container[39m[38;5;252m [39m[38;5;252mvms[39m[38;5;252m [39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--destination-blob[39m[38;5;252m [39m[38;5;252mDESTINATION-blob.vhd[39m
|
||||
@@ -81,10 +86,34 @@
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252msnapshot[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;252mIC-EXASOL-001[39m[38;5;252m [39m[38;5;252m--source[39m[38;5;252m [39m[38;5;252mvm1-disk1[39m[38;5;252m [39m[38;5;252m-n[39m[38;5;252m [39m[38;5;252mvm1-snap1[39m
|
||||
|
||||
[38;5;246;03m# create SAS url for a snapshot[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252msnapshot[39m[38;5;252m [39m[38;5;252mgrant-access[39m[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;252mIC-EXASOL-001[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;252mvm1-snap1[39m[38;5;252m [39m[38;5;252m--duration-in-seconds[39m[38;5;252m [39m[38;5;67m36000[39m[38;5;252m [39m[38;5;252m--query[39m[38;5;252m [39m[38;5;214m'[accessSas]'[39m[38;5;252m [39m[38;5;252m-o[39m[38;5;252m [39m[38;5;252mtsv[39m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252msnapshot[39m[38;5;252m [39m[38;5;252mgrant-access[39m[38;5;252m [39m[38;5;252m--resource-group[39m[38;5;252m [39m[38;5;252mIC-EXASOL-001[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;252mvm1-snap1[39m[38;5;214m\[39m
|
||||
[38;5;252m [39m[38;5;252m--duration-in-seconds[39m[38;5;252m [39m[38;5;67m36000[39m[38;5;252m [39m[38;5;252m--query[39m[38;5;252m [39m[38;5;214m'[accessSas]'[39m[38;5;252m [39m[38;5;252m-o[39m[38;5;252m [39m[38;5;252mtsv[39m
|
||||
|
||||
[38;5;246;03m# attach disk[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mdisk[39m[38;5;252m [39m[38;5;252mattach[39m[38;5;252m [39m[38;5;252m--vm-name[39m[38;5;252m [39m[38;5;252mvm1[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mRESOURCE_GROUP[39m[38;5;252m [39m[38;5;252m--disk[39m[38;5;252m [39m[38;5;252mDISK1_ID[39m
|
||||
|
||||
[38;5;246;03m# detach disk[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mdisk[39m[38;5;252m [39m[38;5;252mdetach[39m[38;5;252m [39m[38;5;252m--vm-name[39m[38;5;252m [39m[38;5;252mvm1[39m[38;5;252m [39m[38;5;252m-g[39m[38;5;252m [39m[38;5;252mRESOURCE_GROUP[39m[38;5;252m [39m[38;5;252m--name[39m[38;5;252m [39m[38;5;252mDISK1_ID[39m
|
||||
|
||||
[48;5;8m[24m tldr:az [24m[0m
|
||||
[38;5;246;03m# az[39;00m
|
||||
[38;5;246;03m# The official CLI tool for Microsoft Azure.[39;00m
|
||||
[38;5;246;03m# More information: <https://docs.microsoft.com/cli/azure>.[39;00m
|
||||
|
||||
[38;5;246;03m# Log in to Azure:[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mlogin[39m
|
||||
|
||||
[38;5;246;03m# Manage azure subscription information:[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252maccount[39m
|
||||
|
||||
[38;5;246;03m# List all Azure Managed Disks:[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mdisk[39m[38;5;252m [39m[38;5;252mlist[39m
|
||||
|
||||
[38;5;246;03m# List all Azure virtual machines:[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mvm[39m[38;5;252m [39m[38;5;252mlist[39m
|
||||
|
||||
[38;5;246;03m# Manage Azure Kubernetes Services:[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252maks[39m
|
||||
|
||||
[38;5;246;03m# Manage Azure Network resources:[39;00m
|
||||
[38;5;252maz[39m[38;5;252m [39m[38;5;252mnetwork[39m
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
[48;5;8m[24m cheat:ls [24m[0m
|
||||
[38;5;246;03m# To display everything in <dir>, excluding hidden files:[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m<[39m[38;5;252mdir>[39m
|
||||
|
||||
@@ -15,3 +16,28 @@
|
||||
|
||||
[38;5;246;03m# To display directories only, include hidden:[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m-d[39m[38;5;252m [39m[38;5;252m.*/[39m[38;5;252m [39m[38;5;252m*/[39m[38;5;252m [39m[38;5;252m<[39m[38;5;252mdir>[39m
|
||||
|
||||
[48;5;8m[24m tldr:ls [24m[0m
|
||||
[38;5;246;03m# ls[39;00m
|
||||
[38;5;246;03m# List directory contents.[39;00m
|
||||
|
||||
[38;5;246;03m# List files one per line:[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m-1[39m
|
||||
|
||||
[38;5;246;03m# List all files, including hidden files:[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m-a[39m
|
||||
|
||||
[38;5;246;03m# List all files, with trailing `/` added to directory names:[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m-F[39m
|
||||
|
||||
[38;5;246;03m# Long format list (permissions, ownership, size and modification date) of all files:[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m-la[39m
|
||||
|
||||
[38;5;246;03m# Long format list with size displayed using human readable units (KB, MB, GB):[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m-lh[39m
|
||||
|
||||
[38;5;246;03m# Long format list sorted by size (descending):[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m-lS[39m
|
||||
|
||||
[38;5;246;03m# Long format list of all files, sorted by modification date (oldest first):[39;00m
|
||||
[38;5;252mls[39m[38;5;252m [39m[38;5;252m-ltr[39m
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#[cheat:ls]
|
||||
# To display everything in <dir>, excluding hidden files:
|
||||
ls <dir>
|
||||
|
||||
@@ -15,3 +16,27 @@ ls -d */ <dir>
|
||||
|
||||
# To display directories only, include hidden:
|
||||
ls -d .*/ */ <dir>
|
||||
#[tldr:ls]
|
||||
# ls
|
||||
# List directory contents.
|
||||
|
||||
# List files one per line:
|
||||
ls -1
|
||||
|
||||
# List all files, including hidden files:
|
||||
ls -a
|
||||
|
||||
# List all files, with trailing `/` added to directory names:
|
||||
ls -F
|
||||
|
||||
# Long format list (permissions, ownership, size and modification date) of all files:
|
||||
ls -la
|
||||
|
||||
# Long format list with size displayed using human readable units (KB, MB, GB):
|
||||
ls -lh
|
||||
|
||||
# Long format list sorted by size (descending):
|
||||
ls -lS
|
||||
|
||||
# Long format list of all files, sorted by modification date (oldest first):
|
||||
ls -ltr
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
[48;5;8m[24m cheat.sheets:btrfs [24m[0m
|
||||
[38;5;246;03m# Create a btrfs file system on /dev/sdb, /dev/sdc, and /dev/sdd[39;00m
|
||||
[38;5;252mmkfs.btrfs[39m[38;5;252m [39m[38;5;252m/dev/sdb[39m[38;5;252m [39m[38;5;252m/dev/sdc[39m[38;5;252m [39m[38;5;252m/dev/sdd[39m
|
||||
|
||||
@@ -52,3 +53,22 @@
|
||||
|
||||
[38;5;246;03m# convert btrfs to ext3/ext4[39;00m
|
||||
[38;5;252mbtrfs-convert[39m[38;5;252m [39m[38;5;252m-r[39m[38;5;252m [39m[38;5;252m/dev/sdb1[39m
|
||||
|
||||
[48;5;8m[24m tldr:btrfs [24m[0m
|
||||
[38;5;246;03m# btrfs[39;00m
|
||||
[38;5;246;03m# A filesystem based on the copy-on-write (COW) principle for Linux.[39;00m
|
||||
|
||||
[38;5;246;03m# Create subvolume:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252msubvolume[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252mpath/to/subvolume[39m
|
||||
|
||||
[38;5;246;03m# List subvolumes:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252msubvolume[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252mpath/to/mount_point[39m
|
||||
|
||||
[38;5;246;03m# Show space usage information:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252mfilesystem[39m[38;5;252m [39m[38;5;252mdf[39m[38;5;252m [39m[38;5;252mpath/to/mount_point[39m
|
||||
|
||||
[38;5;246;03m# Enable quota:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252mquota[39m[38;5;252m [39m[38;5;31menable[39m[38;5;252m [39m[38;5;252mpath/to/subvolume[39m
|
||||
|
||||
[38;5;246;03m# Show quota:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252mqgroup[39m[38;5;252m [39m[38;5;252mshow[39m[38;5;252m [39m[38;5;252mpath/to/subvolume[39m
|
||||
|
||||
+14
-1
@@ -1,4 +1,4 @@
|
||||
[48;5;8m[24m btrfs [24m[0m
|
||||
[48;5;8m[24m cheat.sheets:btrfs [24m[0m
|
||||
[38;5;246;03m# create the subvolume /mnt/sv1 in the /mnt volume[39;00m
|
||||
[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252msubvolume[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252m/mnt/sv1[39m
|
||||
|
||||
@@ -13,3 +13,16 @@
|
||||
|
||||
[38;5;246;03m# taking snapshot of a subvolume[39;00m
|
||||
[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252msubvolume[39m[38;5;252m [39m[38;5;252msnapshot[39m[38;5;252m [39m[38;5;252m/mnt/sv1[39m[38;5;252m [39m[38;5;252m/mnt/sv1_snapshot[39m
|
||||
|
||||
[48;5;8m[24m tldr:btrfs [24m[0m
|
||||
[38;5;246;03m# Create subvolume:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252msubvolume[39m[38;5;252m [39m[38;5;252mcreate[39m[38;5;252m [39m[38;5;252mpath/to/subvolume[39m
|
||||
|
||||
[38;5;246;03m# List subvolumes:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252msubvolume[39m[38;5;252m [39m[38;5;252mlist[39m[38;5;252m [39m[38;5;252mpath/to/mount_point[39m
|
||||
|
||||
[38;5;246;03m# Enable quota:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252mquota[39m[38;5;252m [39m[38;5;31menable[39m[38;5;252m [39m[38;5;252mpath/to/subvolume[39m
|
||||
|
||||
[38;5;246;03m# Show quota:[39;00m
|
||||
[38;5;252msudo[39m[38;5;252m [39m[38;5;252mbtrfs[39m[38;5;252m [39m[38;5;252mqgroup[39m[38;5;252m [39m[38;5;252mshow[39m[38;5;252m [39m[38;5;252mpath/to/subvolume[39m
|
||||
|
||||
Reference in New Issue
Block a user